Missing posts in a query

时间:2015-04-09 作者:user3679718

我有一个循环,我需要获取一个自定义的帖子类型,获得一个分类法,然后对于分类法中的每个术语,我需要输出所有帖子。它们都是在库中输出的,其中分类术语是标题,帖子是库中的项目(我使用http://bit.ly/1jCf2Wj). 我有这样的想法:

<?php 

        global $post;
        $post_type = \'people\';
        $taxonomies = get_object_taxonomies( (object) array( \'post_type\' => $post_type ) );
        $tax = $taxonomies[0];
        $terms = get_terms( $tax );

        //make the query
        $people_args = array( \'post_type\' => $post_type);  
        $loop = new WP_Query( $people_args ); //look for people posts
        $termsLength = count($terms);// count terms in the taxonomy, returns correct number

        //for each people post
        while ( $loop->have_posts() ) : $loop->the_post();

        //for each term in the taxonomy
        for ($x = 0; $x <= $termsLength-1; $x++) {
          //this is all posts looped by terms length - 1 

          //if the post has got the name (department name) in $tax (departments group)
          if( has_term( $terms[$x]->name, $tax ) ) {

            echo \'<div style="display:block;clear:both; margin-left:0px; z-index:9999; ">\'. $terms[$x]->name .\'</div>\';

            // echo \'<div style="display:block;clear:both; margin-left:990px; z-index:9999;">\'.$wp_query->post_count.\'</div>\';
            $name = $terms[$x]->name; // dept name
            $title = get_the_title($post->ID); // the post title
            $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'thumbnail_size\' ); // the post thumb
            $url = $thumb[\'0\']; // url to thumb
            echo \'<li data-pile="\'. $name .\'">\';
            echo \'<a href="#">\';
            echo \'<span class="tp-info"><span>\'.$title.\'</span><span class="profile-smaller">\'. get_post_meta($post->ID, \'position\', true).\'</span></span>\';
            echo \'<img src="\'. $url .\'" />\';
            echo \'</a></li> \';

          }
        }

        endwhile;
        rewind_posts(); wp_reset_query();

        ?>
我得到了查询的结果,但并不是所有的帖子都在那里。如果我发布的帖子多于x,那么其中一个分类术语(部门)就不会出现。另一个分类术语只显示一篇文章。

我在哪里犯错?

1 个回复
SO网友:user3679718

事实证明,对我来说,在每页上设置明确的帖子是可行的。

结束

相关推荐

使用DATE_QUERY获取下一个事件

我创建了一个名为event的CPT,并希望根据它的发布日期进行查询以显示下一个将来的事件。这是WP_Query 参数:$today = getdate(); $args = array( \'post_status\' => array(\'publish\', \'future\'), \'post_type\' => \'event\', \'orderby\' => \'date\', \'order\' =&