[wp-hackers] Adding pagination to custom/complex pretty (search) permalinks

Tom Barrett tcbarrett at gmail.com
Fri Feb 22 13:42:15 UTC 2013


I've added 3 additional query_vars to WordPress. One is an end point (and
hopefully not relevant).

The other two are used to drill through search results, and I would like
them paginated. They are 'mycat' (custom taxonomy) and 'distance' (value
derived using SQL query).

I have three rewrites:
  add_rewrite_rule( '^search/([^/]+)/mycat/([^/]+)/distance/([^/]+)',
'index.php?s=$matches[1]&mycat=$matches[2]&distance=$matches[3]', 'top' );
  add_rewrite_rule( '^search/([^/]+)/mycat/([^/]+)',
 'index.php?s=$matches[1]&mycat=$matches[2]',                      'top' );
  add_rewrite_rule( '^search/([^/]+)/distance/([^/]+)',
'index.php?s=$matches[1]&distance=$matches[2]',                   'top' );

These are all working fine. However pagination doesn't work out of the box.
Will I have to manually add all the page=>paged and double up my rewrites?
Or is there a nice way to get WP to pass along the pagination?

These all work:
/search/pianist/
/search/pianist/page/2/
/search/pianist/mycat/gold/
/search/pianist/distance/50/
/search/pianist/mycat/gold/distance/50/

The first two get picked up by core, the latter 3 by my rewrites.

These don't work:
/search/pianist/mycat/gold/page/2/
/search/pianist/distance/50/page/2/
/search/pianist/mycat/gold/distance/50/page/2/

I can just add a rule for each:
  add_rewrite_rule( '^search/([^/]+)/distance/([^/]+)/page/([^/]+)',
'index.php?s=$matches[1]&distance=$matches[2]&page=$matches[3]',  'top' );
  ...

But wondered if there was a nicer way?

Tom

-- 
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett


More information about the wp-hackers mailing list