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 am trying to get three loops to display. they all belong to the same post type and the same taxonomy family. but i'm trying to separate the taxonomy by three different values.

$argsOwners = array( 'tax_query' => array(array('taxonomy' => 'position',  'field' => 'slug', 'terms' => 'senior-management'    )));
$the_query_owners = new WP_Query( $argsOwners );

then i

<?php wp_reset_postdata(); // reset the query ?>

then i

$argsSales = array( 'tax_query' => array(array('taxonomy' => 'position',  'field' => 'slug', 'terms' => 'sales' )));
$the_query_sales = new WP_Query( $argsSales );

and i repeat again for the third term of "admin". the problem is only the first query will work. any ideas?

EDIT EDIT EDIT

I think i figure what the issue is. It had to do with whether is was logged in or not. if i was logged in then i would only see the for query displayed. but if im logged out then i get all 3 perfectly.

share|improve this question
    
Try adding wp_reset_query() after each query instead of wp_reset_postdata() –  Bainternet Jun 17 '11 at 15:56
    
i tried that as well. it didn't work. –  Steve Fischer Jun 17 '11 at 19:39
    
What else is going on in the theme file that could 'upset' things? And do you have any plugins activated, and if so, which ones? –  TheDeadMedic Jun 17 '11 at 20:14
add comment

2 Answers 2

up vote 1 down vote accepted

As @TheDeadMedic said, you've to work like that. in the default loop like:

while( have_posts() ) : the_post

endwhile;

in this case, the loop is running with the default $wp_query variable. But as you are running custom queries, you need to use while( $query_obj->have_posts() ) : $query_obj->the_post(); like that

But while logged in and logged out, you shouldn't get different results :S

share|improve this answer
add comment

Are you calling $obj->the_post(), as opposed to just the_post()? For example;

/* Senior Management */
$query_args = array( 'tax_query' => array( array( 'taxonomy' => 'position',  'field' => 'slug', 'terms' => 'senior-management' ) ) );
$query_obj = new WP_Query( $query_args );

while( $query_obj->have_posts() ) : $query_obj->the_post();

    // do senior-management stuff here

endwhile;


/* Sales */
$query_args['tax_query'][0]['terms'] = 'sales';
$query_obj->query( $query_args );

while( $query_obj->have_posts() ) : $query_obj->the_post();

    // do sales stuff here

endwhile;


/* Marketing */
$query_args['tax_query'][0]['terms'] = 'marketing';
$query_obj->query( $query_args );

while( $query_obj->have_posts() ) : $query_obj->the_post();

    // do marketing stuff here

endwhile;

If you're doing the same 'stuff' for each loop, you could cut down your code even more by running it in a foreach over an array of position terms.

share|improve this answer
    
Ok, yes I do like that much better. I will probably change it to that. –  Steve Fischer Jun 17 '11 at 19:37
    
Please look at me edit. If i'm right and it does have something to do with being logged in can someone please explain to me WHY WHY WHY would that matter??? –  Steve Fischer Jun 17 '11 at 19:41
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.