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.
As Toscho mentionned above, you didn’t close your
if
andwhile
. When in doubt, indent your codes to avoid confusion.Also, you don’t need to use
wp_reset_query()
with WP_Query. This question deals with that issue.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.