Monthly Archives: March 2017

Custom Taxonomy Archive Template Paginiation Notes

Five things you need for custom taxonomy archive page pagination working perfectly :

( 1 ) Don’t put exclude_from_search parameter key as register_post_type argument parameter or if mention set it ‘exclude_from_search’ => false. By default it is set false if not mentioned.

( 2 ) The taxonomy that will be use with the custom post type set
‘taxonomies’ => ‘custom_taxonomy_name’ as register_post_type argument parameter or
use register_taxonomy_for_object_type() directly.
Custom taxonomies still need to be registered with register_taxonomy().

( 3 ) While querying within new WP_Query ($args)
i ) If not set in admin static front page use before new WP_Query($args)
$paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1;
and use $query = new WP_Query( array( ‘paged’ => $paged ) );

ii ) If set in admin static front page use before new WP_Query($args)
$paged = ( get_query_var(‘page’) ) ? get_query_var(‘page’) : 1;
and use $query = new WP_Query( array( ‘page’ => $paged ) );
Remember to use ‘posts_per_page’ and ‘paged’ parameter in new WP_Query($arg) argument array.
If not set static front page then you should use ‘page’ parameter in new WP_Query ($arg) argument array

( 4 ) Use WordPress paginate_links( $args ) function like the example below to render pagination in archive template file.

$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%', or '/paged=%#%', // if using pretty permalink
'current' => max( 1, get_query_var('paged') ),
'total' => $query->max_num_pages ) );
// Here $max_num_pages is the properties of new WP_Query() object . It is total number of pages. Is the result of $found_posts / $posts_per_page

( 5 ) The paginate_links() function output the html.

  • .......

If you use bootstrap inject “pagination” class to the

    with the help of javascript or jquery and a nice fancy pagination will be output.