要扩展@s\\u ha\\u dum的答案,您需要修改有关查询的一些内容。
首先,使用他建议的税务查询:
$args = array(
\'post_type\' => \'custcpt\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'custtax\',
\'field\' => \'id\',
\'terms\' => $cat->term_id,
)
),
\'order\' => \'ASC\'
);
然后,按如下方式修改代码:
$cat_posts = new WP_Query($args);
while ($cat_posts->have_posts()) :
$cat_posts->the_post();
// Below, when referencing the post variables, must be as $cat_post->post->ID, etc. ?>
<center><?php get_the_post_thumbnail($cat_post->post->ID, \'thumbnail\'); ?></center>
<br />
<?php // Below, don\'t need to pass the post ID into these functions. ?>
<a href="<?php get_permalink(); ?>"><?php get_the_title(); ?></a>
<br />
<br />
<?php endwhile; ?>
<?php endif; ?>
请注意以下几点:
您必须使用while ($cat_posts->have_posts)
在立柱上迭代拨打电话cat_posts->the_post()
准备要在功能中显示的数据,如get_the_title()
引用post变量(如ID)时,必须按照$cat_posts->post->ID
调用函数时,如get_the_title()
, 您不需要输入ID