I have a WP_Query
with rewind_posts
that I use to filter posts if they belong to a particular category. Basically, if any post belongs in a category with First
, it goes to the top of the list.
The loop does that, the only problem is that it creates duplicate posts. The post that's in the First
category is at the top and it's also with the rest of the group.
Example of my problem:
- Title - First
- Title 2
- Title 3
- Title - First
- Title 4
- Title 5
Any ideas on how to fix this? This is the code I'm using for the loop:
<?php $args = array(
'tax_query' => array(
array(
'taxonomy' => 'post-status',
'field' => 'slug',
'terms' => array ('post-status-published')
)
)
); $query = new WP_Query( $args );?>
<div class="container">
<?php if ( have_posts() ) {
while( $query->have_posts() ) {
$query->the_post(); ?>
<?php if (in_category('First') ) { ?>
<?php the_title();?><br />
<?php }
} // end first while loop
rewind_posts(); // rewind loop so we can rerun it ?>
<?php while( $query->have_posts() ) { // Start second while loop
$query->the_post(); ?>
<?php if (in_category('Second') ) { ?>
<?php the_title();?><br />
<?php }
} // end first while loop
rewind_posts(); // rewind loop so we can rerun it ?>
<?php while( $query->have_posts() ) { // Start second while loop
$query->the_post(); ?>
<?php the_title();?><br />
<?php } // end second while loop
rewind_posts(); // rewind loop so we can rerun it
} // End your if statement ?>
Thanks for the help.