[英]list of all post from the current taxonomy of custom post type
我创建自定义后类型(CPT)称为circular
。 并为CPT的分类是circular_category
在WordPress
我要实现的是在当前分类页面中生成所有循环自定义帖子类型的标题列表。 固定链接/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();?>
我已更改查询及其工作,如果有人需要,请在此处给出答案
$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 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.