WordPress Taxonomy Template Pagination Issue
-
After dedicating hours on this issue I finally decided to ask the community about the problem I am facing. This issue itself is somewhat interesting and strange.
I created a custom taxonomy template and while I am using the default wordpress loop I am facing issues in Pagination. The posts in every page are coming randomly.
So lets say if I am on page
1
of the taxonomy pagination it shows me2
posts and if I go to page2
it shows me4
posts then2
and then3
posts per page ..I have set the
posts_per_page
as6
usingpre_get_posts
action on myfunctions.php
file ..I am giving the brief codes below ..
TEMPLATE FILE
<?php get_header(); ?> <?php global $wp_query; $big = 999999999; // need an unlikely integer $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; ?> <div <?php post_class('main-section page-inner-wrapper'); ?>> <?php get_template_part('talent_filter', 'talent_filter.php'); ?> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <!-- POST HTML --> <?php endwhile; ?> <!-- PAGINATION BEGIN --> <nav class="navigation pagination" role="navigation"> <?php echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => $paged, 'prev_text' => __( '<i class="fa fa-angle-left"></i>', 'bridge' ), 'next_text' => __( '<i class="fa fa-angle-right"></i>', 'bridge' ), 'before_page_number' => '<span class="meta-nav">' . __( '', 'bridge' ) . ' </span>', 'total' => $wp_query->max_num_pages ) ); ?> </nav> <!-- PAGINATION END --> <?php endif; ?> </div> <?php get_footer(); ?>
FUNCTIONS IN
function.php
function my_post_queries( $query ) { // do not alter the query on wp-admin pages and only alter it if it's the main query if (!is_admin() && $query->is_main_query()){ // alter the query for the home and category pages if( is_tax( 'talent_groups' ) ) { $query->set('posts_per_page', 6); $query->set('posts_per_archive_page', 6); $query->set('orderby', 'date'); } } } add_action( 'pre_get_posts', 'my_post_queries'); // Solves Pagination Pages 404's add_filter( 'option_posts_per_page', 'tdd_tax_filter_posts_per_page' ); function tdd_tax_filter_posts_per_page( $value ) { return (is_tax('talent_groups')) ? 1 : $value; }
- The topic ‘WordPress Taxonomy Template Pagination Issue’ is closed to new replies.