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.

Hi I am trying to add post from a certain taxonomy term to a cpt loop. The code below is the code I am using.

    <?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',
                );
               $my_query = new WP_Query( $args );
if ($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post(); ?>

But the problem with the code is that all of my post are now missing. I then learned that I needed to add a second loop. Ok so after reading up on WP_Query

I tried to add a second loop but it gave me an error, and here is the code i used for that

        <?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',
                );
               $my_query = new WP_Query( $args );
if ($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post(); 

// Restore original Query & Post Data
wp_reset_query();
wp_reset_postdata();

/* The 2nd Query (without global var) */
$query2 = new WP_Query( $args2 );

// The 2nd Loop
if ($query2->have_posts()) : while($query2->have_posts()) : $query2->the_post();

// Restore original Query & Post Data
wp_reset_query();
wp_reset_postdata();

?>

It gave me this error

Parse error: syntax error, unexpected $end in /hermes/bosweb/web188/b1885/ipg.celebloidcom1/tvcafe/wp-content/themes/tvcafe/archive-pretty-little-liars.php on line 258

What am I doing wrong here, can anyone help me fix this. I am not going for a seperated structure in my loop but more of a together structure.

For Example I don't want the first loop at the top and the second loop at the bottom. I want them combined in one loop.

If you need more info or would like to see my whole php please let me know.

share|improve this question
    
Your if(): has to be closed, the while(): too. See syntax. –  toscho Jan 4 '13 at 2:03
    
@toscho it says i have to add endif; do I add that after each wp_reset_postdata(); ....if so i tried that but it didn't work. If i have to add <?php endif; ?> if so that I'm not sure it will work because i have php count codes in my loop as well, were can i upload the whole php file for you to see. –  Mihad Aiko Jan 4 '13 at 2:15
add comment

2 Answers

As Toscho mentionned above, you didn't close your if and while. When in doubt, indent your codes to avoid confusion.

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

/* The 2nd Query (without global var) */
$query2 = new WP_Query( $args2 );

// The 2nd Loop
if ($query2->have_posts()) :
  while($query2->have_posts()) :
    $query2->the_post();
  endwhile;
endif;
wp_reset_postdata();

Also, you don't need to use wp_reset_query() with WP_Query. This question deals with that issue.

share|improve this answer
    
Hi thank you, but now it's only showing one post –  Mihad Aiko Jan 4 '13 at 5:10
    
You should set up your query parameters properly. Read this: codex.wordpress.org/Class_Reference/WP_Query –  RRikesh Jan 4 '13 at 5:25
    
here is the archive file --> gist.github.com/4450181 –  Mihad Aiko Jan 4 '13 at 5:30
    
You didn't declare $args2 in the second WP_Query. You could do a print_r($my_query) and print_r($query2) to see the parameters, results and SQL used in the query. You didn't display anything in the loop either. $my_query->the_post(); will not display your post content. Read this: codex.wordpress.org/The_Loop –  RRikesh Jan 4 '13 at 5:46
    
do you mean $args2=array .... how exactly do i declare $args2 i do have this line for the second loop $query2 = new WP_Query( $args2 ); –  Mihad Aiko Jan 4 '13 at 5:50
show 6 more comments

Looking at your file you never declare $args2, also your page is really not written correctly. You are only getting one post because you are not in the loop properly, it is assuming it is inside a loop but it isn't.

share|improve this answer
    
I am new to this, I know somethings but this is my first time trying to mess with the loop, but can you tell me or show me exactly how to loop it properly. This is for a custom post type archive, each custom post type archive has a different style sheet as well. –  Mihad Aiko Jan 4 '13 at 5:45
    
I think you need a bit more fundamentals with the loop. wp.tutsplus.com/tutorials/theme-development/… –  Dennis Smolek Jan 6 '13 at 3:57
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.