我正在创建名为circular
的自定义帖子类型(cpt)。 cpt 的分类法在wordpress中是circular_category
我想要实现的是在当前分类页面中生成所有循环自定义帖子类型的标题列表。
永久链接/circular_category/free-circular/
我尝试使用此代码没有运气,任何想法? 以下是一些可以添加到查询中的变量
$cir_cat = $wp_query->get_queried_object();
$cat_name = $cir_cat->name;
$cat_id = $cir_cat->term_id;
$cat_slug = $cir_cat->slug ;
查询
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'circular',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'post_title',
'category__in' => $cat_id,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'circular_category',
)
)
);
$circular_query = new WP_Query( $args );
现在显示当前cpt类别
中的列表cpt帖子<ul id="circulars">
<?php
if($circular_query->have_posts()) :
while($circular_query->have_posts()) : $circular_query->the_post();
?>
<li>
<a href="<?php the_permalink() ?>" title="Link to <?php the_title_attribute() ?>">
<?php get_the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php
$total_pages = $circular_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/pages/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
?>
<?php else :?>
<h3><?php _e('No Circular found', ''); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
答案 0 :(得分:0)
我已经更改了查询及其作品我在这里给出了答案,如果有人需要
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'circular',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'post_title',
'paged' => $paged,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'circular_category',
'field' => 'slug',
'terms' => $cat_slug
)
),
);
$circular_query = new WP_Query( $args );