Back to Top

How to Paginate WordPress Taxonomy?

To use Pagination with Taxonomy in wordpress

It is very interesting and exciting to work in wordpress and this time I am going to explain to use paginate taxonomy in WordPress.

Usually, we use pagination with post and custom post types.Its easy to use pagination with post when you are using while loop and have_post function.

But to use same pagination function,its not quite simple to use with taxonomy or custom taxonomy. because you will bel get ‘404 – Not Found’ errors when trying to link url with < taxonomy_url >/page/2

Read about: To import terms from csv in wordpress

So, Let’s understand code which will be work with taxonomy loop:

//get_query_var to get page id from url
$page = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

// number of tags to show per-page
$per_page = 10;

//count total number of terms related to passed taxonomy
$number_of_series = count(get_terms('categories'));
$offset = ( $page - 1 ) * $per_page;

$term_args = array(
    'number' => $per_page,
    'offset' => $offset
$terms = get_terms('categories', $term_args);

if ($terms) {
    foreach ($terms as $term) {
		//your code goes here
	//foreach ends
	// if (function_exists("pagination")) {
		$big = 999999999;

		//your function for pagination or plugin you added for pagination
		echo paginate_links(array(
							'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
							'format' => '?paged=%#%',
							'current' => $paged,
							'total' => ceil($number_of_series / $per_page) // like 10 items per page
} //if ends

That’s it.It’s a wrap!.This concludes today’s tutorial! I’m hoping that you’ve found this tutorial useful.

Read: Pagination when getting posts from category in WordPress

Don’t hesitate to use this code in your WordPress projects and post your comments if you need help. As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (4)

  1. Hi
    Thanks for this, Works like a dream

  2. Hi, I have a problem when using your code with my custom post type taxonomy. The pagination works but the link does not. It always turn to 404 error. Unable to get
    Could you help me with this. Thank you so much!

  3. Markus Bäck says:

    works 😉

  4. Bittu Debnath says:

    This code did not work for me, Tried it in my custom taxonomy page.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Triggers in MySQL

Posted on 7 years ago


What is Reflection in PHP

Posted on 3 years ago


How to create MySQL User Defined Functions

Posted on 7 years ago


Hello world

Updated 5 days ago

Nick Carter

In depth Understanding of Laravel Core

Updated 2 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 4 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 5 years ago