Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Do you use those queries on same page? or is there any other queries like WordPress's default loop? –  Mamaduka Mar 22 '12 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 '12 at 14:16
add comment

2 Answers

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

share|improve this answer
add comment
up vote 0 down vote accepted

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!

share|improve this answer
    
Did this resolve your issue though? You don't seem to be querying for any taxonomies? –  mrwweb May 1 '12 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 '12 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 '12 at 19:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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