【问题标题】:WordPress displaying custom post type posts by custom taxonomyWordPress 按自定义分类显示自定义帖子类型帖子
【发布时间】:2016-04-26 21:19:42
【问题描述】:

我有一个自定义帖子类型 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>

谁能帮帮我,非常感谢!!

【问题讨论】:

  • new wp_query 应该是 new WP_Query

标签: php wordpress twitter-bootstrap post


【解决方案1】:

您可以使用更简单的参数查询:

$postArg = array(
  'post_type'=>'logie',
  'posts_per_page'=>-1,
  'order'=>'desc',
  'logietype' => $catVal->term_id
);

顺便说一下,我建议使用更原生的

<?php the_title(); ?>

如果需要可以上钩。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 2013-06-22
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多