I have a WP_Query which has the "posts_per_page" parameter set to 12. I am then using a while loop to iterate over all of the posts and an IF statement to check whether a condition is true or false. I would like to be able to display 12 posts which return true however, the loop is obviously also counting each post returning false and displaying nothing. For example, 5 posts would be displayed but the other 7 are not displayed.
$args = array(
'post_type' => $post_slug,
'posts_per_page' => 12,
'paged' => 1,
'post_status' => 'publish',
);
$topicsHub = new WP_Query($args);
<?php while ( $topicsHub->have_posts() ) : $topicsHub->the_post();
$resource_type = get_post_type();
if($resource_type == 'tools') {
$stream = get_field('stream_name', get_the_ID());
$tooltype = get_field('tools_type', get_the_ID());
$stream_name = $stream;
foreach ($options['streams'] as $key => $subscription) {
if(in_array($subscription['parent_stream_name'], $stream)){
$stream_name = [];
$stream_name[] = $subscription['name'];
break;
}
}
// Custom function
if(check_if_user_has_access($stream_name, 'something')) {
if($tooltype == 'free') {
continue;
}
} else {
if($tooltype == 'premium') {
continue;
}
}
}
?>
<div class="u-12 u-6@sm u-4@md resource__main-tab--item">
<?php get_template_part('partial/content', 'topics-card'); ?>
</div>
<?php endwhile; ?>
I understand why this is happening but am not sure how I could only show 12 posts that only return true.