WordPress 按自定义分类显示自定义帖子类型帖子


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(); ?>

如果需要,可以钩住。