[英]WordPress displaying custom post type posts by custom taxonomy
我有一个自定义帖子类型的logie
,它具有一个自定义分类法,现在有3个选项。
我的目标是在不同的引导行中按分类显示每个分类,例如:
分类标题1
发布发布发布
分类标题2
发布发布发布
分类标题3
发布发布发布
因此,每个Post
都是上校,标题和帖子都是连续的
这就是我的代码现在的样子。 标题有效,但要获取帖子则有些棘手。 我没有收到任何令人讨厌的错误...
<div class="container-full">
<?php foreach ($cat as $catVal):
$postArg = array('post_type'=>'logie','posts_per_page'=>-1,'order'=>'desc',
'tax_query' => array(
array(
'taxonomy' => 'logietype',
'field' => 'term_id',
'terms' => $catVal->term_id
)
));
$getPost = new wp_query($postArg);
global $post;
?>
<div class="row">
<h2><?php echo $catVal->name; ?></h2>
<?php if($getPost->have_posts()): ?>
<?php while ( $getPost->have_posts()):$getPost->the_post(): ?>
<div class="col-md-4">
<?php echo $post->post_title; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
任何人都可以帮助我,非常感谢!
您可以使用更简单的参数查询:
$postArg = array(
'post_type'=>'logie',
'posts_per_page'=>-1,
'order'=>'desc',
'logietype' => $catVal->term_id
);
顺便说一句,我建议使用更原生的
<?php the_title(); ?>
如果需要,可以将其钩住。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.