0

I'm truly stumped here. I have a specific taxonomy for sorting posts into different types of "featured" posts on a news site. Here's the problem: When querying by them the results aren't what they should be. Here's what I have:

$featured_loop = new WP_Query( array( 'featured' => 'home-featured', 'posts_per_page' => '1') );
if ( have_posts() ):
        while ( $featured_loop->have_posts() ) : $featured_loop->the_post();
            the_post(); 

There is then another underneath, with different formatting:

$featured_loop_2 = new WP_Query( array( 'featured' => 'home-featured', 'posts_per_page' => '3', 'offset' => '1') );
if ( have_posts() ):
        while ( $featured_loop->have_posts() ) : $featured_loop->the_post();
            the_post();

The problem is, it is outputting posts that aren't in the taxonomy... although which ones it outputs changes as I tweak it, which I find even more strange. I tried a tax_query, and that didn't seem to solve it either. Any ideas?

I used "Ultimate Taxonomy Manager" to create the taxonomy.

2
  • Do you use those queries on same page? or is there any other queries like WordPress's default loop?
    – Mamaduka
    Mar 22, 2012 at 7:45
  • They're both on the same page, yessir. The loop isn't in there, yet. Each is showing 1 post (the second should show 3) and they're just the two latest, not from the 'featured' taxonomy.
    – Tim
    Mar 22, 2012 at 14:16

2 Answers 2

1

If you're using multiple queries on same page, you should always use wp_reset_query, place it after loops.

0

Turned out to be a silly mistake, of course. If you look closely you see $featured_loop->the_post(); the_post(); . Which means that the_post(); was repeated, accidentally. Glad that's fixed!

3
  • Did this resolve your issue though? You don't seem to be querying for any taxonomies?
    – mrwweb
    May 1, 2012 at 1:10
  • I believe it did. I was querying for the posts in home-featured term of the featured taxonomy. There were other mistakes that I uncovered as I went along, although I don't think that there were any related to the featured-stories functionality.
    – Tim
    May 2, 2012 at 18:57
  • Great. I'm surprised that's working without a tax_query, but I guess if it works it works. Please accept your own answer (the green check mark) to indicate that you found a solution.
    – mrwweb
    May 2, 2012 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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