我有一个组织的网站,我为领导团队创建了一个新页面。我运行了一个查询,查找;“成员”-类别为“的类型”;领导力;。到目前为止,当我将此输出到页面上时,效果很好。我还有子类别;“总裁”;和;“秘书”;我想显示在每个领导的名字旁边。但是,我一打电话get_the_category()
, 一切都变得一团糟,只有一个结果是输出,总统类别不知何故消失了,职位类别为;“总裁”;获取;“秘书”;显示在其旁边。这是相关代码:
<?php
$leaderQuery = new WP_Query(array(
\'posts_per_page\' => -1,
\'post_type\' => \'member\',
\'cat_slug\' => "Leadership"
));
//var_dump($leaderQuery);
while($leaderQuery->have_posts())
{
$postCategories = get_the_category($leaderQuery->the_post());
//$categoryDescription = category_description($postCategories[0]);
//var_dump($postCategories);
$leaderQuery->the_post(); ?>
<div class="post-item">
<p class="headline headline--small"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> - <?php echo get_the_category($leaderQuery->the_post())->name; ?></p>
</div>
<?php
}
wp_reset_postdata();
echo paginate_links();
?>
var_dump($leaderQuery->the_post())
不包含类别信息,但var_dump($postCategories)
做这是var_dump($postCategories)
:array (size=2)
0 =>
object(WP_Term)[1446]
public \'term_id\' => int 7
public \'name\' => string \'Joint Secretary\' (length=15)
public \'slug\' => string \'joint-secretary\' (length=15)
public \'term_group\' => int 0
public \'term_taxonomy_id\' => int 7
public \'taxonomy\' => string \'category\' (length=8)
public \'description\' => string \'B\' (length=1)
public \'parent\' => int 6
public \'count\' => int 1
public \'filter\' => string \'raw\' (length=3)
public \'cat_ID\' => int 7
public \'category_count\' => int 1
public \'category_description\' => string \'B\' (length=1)
public \'cat_name\' => string \'Joint Secretary\' (length=15)
public \'category_nicename\' => string \'joint-secretary\' (length=15)
public \'category_parent\' => int 6
1 =>
object(WP_Term)[1441]
public \'term_id\' => int 6
public \'name\' => string \'Leadership\' (length=10)
public \'slug\' => string \'leadership\' (length=10)
public \'term_group\' => int 0
public \'term_taxonomy_id\' => int 6
public \'taxonomy\' => string \'category\' (length=8)
public \'description\' => string \'\' (length=0)
public \'parent\' => int 0
public \'count\' => int 2
public \'filter\' => string \'raw\' (length=3)
public \'cat_ID\' => int 6
public \'category_count\' => int 2
public \'category_description\' => string \'\' (length=0)
public \'cat_name\' => string \'Leadership\' (length=10)
public \'category_nicename\' => string \'leadership\' (length=10)
public \'category_parent\' => int 0
这是页面上实际输出的当前帖子的错误数据,在这两个帖子中,只有一个显示出来,另一个给出了其类别信息。如何使每个帖子正确检索类别名称并将其显示在帖子标题旁边?