0

I have front-page.php with several loops - one for each category.

$queryX = new WP_Query( array( 'cat' => X, 'posts_per_page' => 6 ) );

                    while ( $queryX->have_posts() ) {
                        ?>
                    <div class="news">
                            <?php
                            $queryX->the_post();
                            ?>
                            <?php the_title( sprintf( '<h6><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h6>' ); ?>
                            <figure>
                            <?php the_post_thumbnail(); ?>
                            </figure>
                        </div>
                        <?php
                    }

                    wp_reset_postdata();
                    ?>

Where X - is number (from 1 to 5, by number of categories). There are few news in every category with unique title, content and thumbnail. The problem with this loop is that first 3 loops work out alright, but 4th one displays 2 posts from 4th category with different titles and links, but the same thumbnail! Even more so, 5th loop also displays with 4th's thumbnail.

That's quite annoying and I don't get what am I missing, because:

  • I've another theme with nearly the same code (it just adds ignore_sticky_posts), and it works out alright.
  • First 3 work out fine.
  • All posts are standard, all categories exists, posts are in right categories.
  • I've tried, albeit for nothing, adding wp_query_reset() to the equation with nu success.

What am I missing?

Much appreciated any response!

0

Missed last two loops had $queryX->the_post(); after the_post_thumbnail(); Now when I changed it - works perfectly! Hope it helps someone!

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.