I have the standard blog post format and gallery format. I have excluded all the gallery posts from the index.php page so only standard posts show up there. However, the gallery format posts are still being counted for pagination and there is just a blank space on the pagination pages where there would be a gallery post format. How can those be excluded from pagination?
<?php echo paginate_links(); ?>
I tried this but it didn't help:
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array(
'post-format-gallery'
) ,
'operator' => 'NOT IN',
) ,
)
);
?>
<?php echo paginate_links($args); ?>
This is the query that displays the standard blog posts:
<?php if (have_posts() ): ?>
<?php while (have_posts() ): the_post(); ?>
<?php $format = get_post_format( $post_id ); ?>
<?php if($format != 'gallery'): ?>
<div class="blog" style="width: 350px"><a href="<?php esc_url(the_permalink()); ?>" class="w-inline-block"><?php the_post_thumbnail(); ?></a>
<div class="gallery-info"><a href="<?php esc_url(the_permalink()); ?>" class="linkgallery"><?php the_title(); ?></a></div>
<?php $the_category = get_the_category(); ?>
<div class="gallery-info gallery-category"><?php foreach($the_category as $category): ?><?php echo $category->cat_name . ' '; ?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
paginate_links()
may not be using the query where you've applied this: "I have excluded all the gallery posts from the index.php". So if it's the main query, you could trywp_reset_query(); echo paginate_links();
. And in the updated question, that args is for theWP_Query
class and not thepaginate_links
function.wp_reset_query()
but still have same result<?php wp_reset_postdata(); echo paginate_links(); ?>
if($format != 'gallery')
to visually exclude the posts. You should use thepre_get_posts
hook, or create a new WordPress query ($query = new WP_Query(...);
) to exclude the posts and have the correct pagination output.