How To A Paginate Custom Taxonomy Archive In WordPress

Trying to paginate a custom taxonomy query in WordPress due to a 404 error on /page/2? All you may need is to add an action in your theme’s functions file.

Setting the query to paginate a custom taxonomy archive

To paginate the custom taxonomy, make sure you first follow the guide on how to paginate custom post types.

Only after, follow the steps below to set the query in order to paginate the archive for the custom taxonomy.

  1. Navigate to Appearance > Editor > Theme Functions (functions.php) from your WordPress website’s dashboard;
  2. Copy and paste in the code below;
  3. Click Update File to save the changes.
function custom_tax_query_change( $query ) {
     if ( ! is_admin() && $query->is_tax( 'example_tax_name' ) ) {
          $query->set( 'posts_per_page', 10 );
add_action( 'pre_get_posts', 'custom_tax_query_change' );

Note, there’s no need to use posts_per_page in your query arguments after using the action above as this will be overridden by this action.