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 using the code below to call post from a certain Taxonomy term. My intentions are to mix that into the normal loop.

I'm am not trying to create two different loops, but one loop that displays the post from the taxonomy term as well as the original post in the loop, all together.

The problem is that the code below made the original loop disappear, what should i do. I am not great at writing code, I am learning. Can someone please help me.

<?php // Create empty array to store post ids in
     $excludes = array();

                     $args=array(
                     'post_type' => array ('gallery','videos'),
         'taxonomy'=>'series',
         'term' => 'pretty-little-liars',
                     'post_status' => 'publish',
                    );
                    query_posts( $args );

if (have_posts()) : while(have_posts()) : the_post(); ?>
share|improve this question
add comment

1 Answer

query_posts will clobber the main query. You've overwritten the original set of posts. Don't use query_posts Instead create a new WP_Query object for your second set of posts, and another Loop.

It sounds like what you are trying to do is overly complicated. "Mixing" two queries is not likely to be worth the effort. It appears that you are going to have two queries anyway, so just run two Loops.

Your first Loop would look like you have it already.

if (have_posts()) : while(have_posts()) : the_post();
  // 
endwhile; endif;

Your second, using a new WP_Query object, would look like:

$my_query = new WP_Query( $args );
if ($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post();
  // 
endwhile; endif;

If you really must "mix" the two Loops then:

$combloop = $posts;
$my_query = new WP_Query( $args );
$combloop = $combloop + $my_query->posts;
foreach ($combloop as $post) {
  setup_postdata($post);
  //
}

Loops really aren't meant to be merged like that. I believe it should work but you could have problems, especially with something like pagination.

share|improve this answer
    
I changed the last two lines of the code to what you have posted but now all of my post are missing. –  Mihad Aiko Jan 3 '13 at 21:01
    
You also need the normal Loop -- if (have_posts()) : while(have_posts()) : the_post(); –  s_ha_dum Jan 3 '13 at 21:14
    
Where do i add that, and how, sorry if I ask of too much I haven't learned this part of php yet. –  Mihad Aiko Jan 3 '13 at 21:35
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.