admin管理员组文章数量:1022670
PHP:
<?php $posts_query = new WP_Query('post_type="posts&posts_per_page=-1"');
if ($posts_query->have_posts()) : while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php if( $posts_query->current_post%5 == 0 ) { echo "\n" . '<div class="column">'; }
elseif( $posts_query->current_post%5 == 2 ) { echo "\n" . '<div class="column">'; } ?>
<article>
<a class="post-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</article>
<?php if( $posts_query->current_post%5 == 1 || $posts_query->current_post%5 == 4 || $posts_query->current_post == $posts_query->post_count-1 ) { echo '</div>'; }
endwhile;
?>
<?php else: endif; ?>
The above code works great, however I've got a total of 8 posts and only 7 are being displayed.
Could someone steer me in the right direction?
Cheers
PHP:
<?php $posts_query = new WP_Query('post_type="posts&posts_per_page=-1"');
if ($posts_query->have_posts()) : while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php if( $posts_query->current_post%5 == 0 ) { echo "\n" . '<div class="column">'; }
elseif( $posts_query->current_post%5 == 2 ) { echo "\n" . '<div class="column">'; } ?>
<article>
<a class="post-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</article>
<?php if( $posts_query->current_post%5 == 1 || $posts_query->current_post%5 == 4 || $posts_query->current_post == $posts_query->post_count-1 ) { echo '</div>'; }
endwhile;
?>
<?php else: endif; ?>
The above code works great, however I've got a total of 8 posts and only 7 are being displayed.
Could someone steer me in the right direction?
Cheers
Share Improve this question asked Oct 7, 2015 at 14:27 Z0idbergZ0idberg 11 silver badge2 bronze badges2 Answers
Reset to default 1There seems to be a syntax in your Query:
post_type="posts&posts_per_page=-1"
would mean that your post type is posts&posts_per_page=-1
I think you mean
$posts_query = new WP_Query('post_type=post&posts_per_page=-1');
(The post type is not posts, but post)
In this case Wordpress would not apply anyhting at all (because it contain errors, but just fetches the default post type with setting (that is set in dashboard) "nr of posts".
My opinion is that you always should array(s) as arguments to the WP_Query, because it's more readable and easier to debug.
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
);
$posts_query = new WP_Query($args);
In your case it would not matter, but when you want to extend functionality to include let's say a taxonomy it would be
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'people',
'field' => 'slug',
'terms' => 'bob',
),
),
);
$query = new WP_Query( $args );
Make sure your posts are all published and that they are not in the trash can.
PHP:
<?php $posts_query = new WP_Query('post_type="posts&posts_per_page=-1"');
if ($posts_query->have_posts()) : while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php if( $posts_query->current_post%5 == 0 ) { echo "\n" . '<div class="column">'; }
elseif( $posts_query->current_post%5 == 2 ) { echo "\n" . '<div class="column">'; } ?>
<article>
<a class="post-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</article>
<?php if( $posts_query->current_post%5 == 1 || $posts_query->current_post%5 == 4 || $posts_query->current_post == $posts_query->post_count-1 ) { echo '</div>'; }
endwhile;
?>
<?php else: endif; ?>
The above code works great, however I've got a total of 8 posts and only 7 are being displayed.
Could someone steer me in the right direction?
Cheers
PHP:
<?php $posts_query = new WP_Query('post_type="posts&posts_per_page=-1"');
if ($posts_query->have_posts()) : while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php if( $posts_query->current_post%5 == 0 ) { echo "\n" . '<div class="column">'; }
elseif( $posts_query->current_post%5 == 2 ) { echo "\n" . '<div class="column">'; } ?>
<article>
<a class="post-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</article>
<?php if( $posts_query->current_post%5 == 1 || $posts_query->current_post%5 == 4 || $posts_query->current_post == $posts_query->post_count-1 ) { echo '</div>'; }
endwhile;
?>
<?php else: endif; ?>
The above code works great, however I've got a total of 8 posts and only 7 are being displayed.
Could someone steer me in the right direction?
Cheers
Share Improve this question asked Oct 7, 2015 at 14:27 Z0idbergZ0idberg 11 silver badge2 bronze badges2 Answers
Reset to default 1There seems to be a syntax in your Query:
post_type="posts&posts_per_page=-1"
would mean that your post type is posts&posts_per_page=-1
I think you mean
$posts_query = new WP_Query('post_type=post&posts_per_page=-1');
(The post type is not posts, but post)
In this case Wordpress would not apply anyhting at all (because it contain errors, but just fetches the default post type with setting (that is set in dashboard) "nr of posts".
My opinion is that you always should array(s) as arguments to the WP_Query, because it's more readable and easier to debug.
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
);
$posts_query = new WP_Query($args);
In your case it would not matter, but when you want to extend functionality to include let's say a taxonomy it would be
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'people',
'field' => 'slug',
'terms' => 'bob',
),
),
);
$query = new WP_Query( $args );
Make sure your posts are all published and that they are not in the trash can.
本文标签: Not all posts showing in query
版权声明:本文标题:Not all posts showing in query 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745498213a2153266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论