Rewrite Rules, Query Vars and Pagination

Putt a lot of research in and did a lot of testing for this issue and I don't think I am going to solve this by myself at this point.

What we have:

A page with a permalink with one shortcode. That shortcode is resolved via plugin, which provides different views / outputs relatively by the url-path:

/dashboard/admin -- the WP page permalink

/dashboard/admin/trainers/list -- path without own permalink

This all works fine with this rule:

dashboard/admin/(.*)

Now to the issue:

/dashboard/admin/trainers/list/page/2

This url doesn't trigger the pagination to go to page 2, the paged var is empty (null).

The rule:

dashboard/trainers/(.+)/page/([0-9]{1,})/?$

This rule matches perfectly with preg_match testers and the test plugin "Rewrite Rules Inspector":

The add_rewrite_rule part:

    $rule = $path.'/(.+)/page/([0-9]{1,})/?$';
    add_rewrite_rule( $rule, 'index.php?pagename=$matches[1]dashview=$matches[2]paged=$matches[3]','top');
    $this-flush($rule);
    $rule = $path.'/(.*)';
    add_rewrite_rule( $rule, 'index.php?pagename='.$path.'dashview=$matches[1]','top');
    $this-flush($rule);

( $path is just "dashboard/admin" )

My rule for paged pages gets overridden by the second rule. How can I prevent that?

Debug I did:

Using a redirect_canonical filter callback, and returning the requested URL with "?paged=2" works, and will get me to page 2 of the list.

Topic paged rewrite-rules Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.