为什么我的循环没有使用自定义帖子类型中的自定义分类术语填充页面?目前,它显示的是一个空框,而不是从我的自定义帖子类型中提取自定义分类术语series
. 我完全不知道为什么会这样。如能提供任何帮助,我们将不胜感激!
<?php
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$args = array(
\'posts_per_page\' => 10,
\'paged\' => $paged,
\'taxonomy\'=> \'series\',
\'field\' => \'slug\',
\'orderby\' => \'ID\',
\'order\' => \'DESC\'
);
$custom_query = new WP_Query( $args );
if ( have_posts() ) : while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div class="block_item article">
<div class="article_image" style="background: url(\'<?php the_field(\'series_artwork\', $term); ?>\'); background-size: cover; background-position: 50%;"></div>
<h4 class="section_label"><?php the_field(\'date\', $term); ?></h4>
<div class="block_item_content">
<h3><?php echo $term->name; ?></h3>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link($term->slug, \'series\'); ?>" class="button_styling">
Read More
</a>
</div>
</div>
<?PHP endwhile; endif; ?>
<div class="clear"></div>
<?php // Pagination
if (function_exists("pagination")) {
pagination($custom_query->max_num_pages);
} ?>
SO网友:Akshat
您需要在参数中指定post类型,并且需要正确使用分类标记。您可以尝试以下args变量。
$args = array(
\'posts_per_page\' => 10,
\'post_type\' => \'series\', //Specify the post type here
\'paged\' => $paged,
\'tax_query\' => array(
array(
\'taxonomy\' => \'\', //specify the taxonomy name
\'field\' => \'slug\',
\'terms\' => \'\', //Specify the slug of what you want from the taxonomy
\'operator\' => \'IN\',
)
)
\'orderby\' => \'ID\',
\'order\' => \'DESC\'
);