0

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

1

There 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 );
0

Make sure your posts are all published and that they are not in the trash can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.