How to fix pagination after rewriting url? ie. www.site.com/players/type/pro/page/3/

You have to add another rule which maps the /page/# to the &paged=# variable.

Really though, you’re kinda doing it all backwards here by filtering the rules array. Just calling add_rewrite_rule to add your rules makes a bit more sense.

function plugin_name_add_rewrite_rules() {
  add_rewrite_rule('players/type/([^/]+)/?$',
   'index.php?post_type=players&type=$matches[1]',
   'top');
  add_rewrite_rule('players/type/([^/]+)/page/([0-9]+)?$',
   'index.php?post_type=players&type=$matches[1]&paged=$matches[2]',
   'top');
}
add_filter('init', 'plugin_name_add_rewrite_rules');

Leave a Comment