user3649628
user3649628

Reputation: 51

Wordpress loop is not showing all posts

I got lots of articles I show on my category page.

Here is the code.

<?php if(is_category(4)) { 
    while ( have_posts() ) : the_post(); ?>
        <div class="work">
            <div class="work-thumb">
                <a href="<?php echo get_permalink(); ?>">
                    <?php the_post_thumbnail(); ?>
                </a>
            </div>
            <div class="work-title">
                <a href="<?php echo get_permalink(); ?>"> <?php the_title(); ?></a>
            </div>
        </div>
    <?php endwhile; // end of the loop.
} ?>

It is just loop on all articles, but it doesn't show all of them, just like 50%

What could be the problem>?

Upvotes: 3

Views: 2614

Answers (1)

Dan.
Dan.

Reputation: 717

Is the page that's using that template/code the page that you have set to be the Posts Page, in admin settings?

If so, then the posts per page setting could be less than the total number of posts (and you would need pagination, or to increase this number).

If it's a custom query with the code in your question, then you need to add this to the query arguments:

'posts_per_page' => -1

Note: Even if your case is the former, you could alter the query by using the pre_get_posts filter. E.g. put this in your theme's functions.php:

add_action('pre_get_posts', 'my_filter');

function my_filter( $query ){
    $query->set('posts_per_page', -1);
    return $query;
}

Inside that function, you want to wrap the code inside an if statement, to do it specifically for the, for example, post type or taxonomy in question.

Upvotes: 2

Related Questions