我试图在标题下显示我的CPT类别以及与之相关的任何帖子。我有第一个循环,很好:
<?php $cats = get_categories(array(\'taxonomy\' => \'custtax\', \'orderby\' => \'term_group\'));
if(!empty($cats)) :
foreach($cats as $cat) : ?>
<a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->name; ?></a>
<br />
<?php wp_reset_query(); ?>
<?php $cat_posts = new WP_Query(array(\'post_type\' => \'custcpt\', \'taxonomy\' => \'custtax\', \'terms\' => $cat->slug, \'order\' => \'ASC\'));
foreach($cat_posts as $cat_post) : ?>
<center><?php get_the_post_thumbnail($cat_post->ID, \'thumbnail\'); ?></center>
<br />
<a href="<?php get_permalink($cat_post->ID); ?>"><?php get_the_title($cat_post->ID); ?></a>
<br />
<br />
<?php endforeach; ?>
<?php endforeach; ?>
<?php endif; ?>
但我的第二个循环查询我的所有帖子,而不仅仅是来自该类别的帖子。我试过了get_posts()
它没有拉所有的柱子,也没有拉任何柱子。我不确定\'category\'
在codex中需要字符串、slug或ID,但我已经尝试了所有3个。无论如何,我如何编辑我的查询以仅从该特定类别中获取帖子?