Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom page that uses a rewrite rule. The "non-pagination" rewrite works fine:

add_rewrite_rule(
     '^brand-list/([^/]*)/([^/]*)/?',
     'index.php?pagename=brand-list&brand=$matches[1]&section=$matches[2]',
     'top'
);

basically a url like this /pagename=brand-list&brand=MyBrand&section=MySection ends up like this, /brand-list/MyBrand/Mysection

However, when using pagination the page number is never returned to wordpress so $paged on page 2 is still 0

add_rewrite_rule(
      '^brand-list/([^/]*)/([^/]*)/page/([0-9]+)?',
      'index.php?pagename=brand-list&brand=$matches[1]&section=$matches[2]&paged=$matches[3]',
      'top'
);

this url, /pagename=brand-list&brand=MyBrand&section=MySection&paged=2, ends up like this, /brand-list/MyBrand/Mysection/page/2 but still shows page 1. Checking the $paged value it outputs as 0, it should be 2.

If I removed the rewrite rules and /pagename=brand-list&brand=MyBrand&section=MySection&paged=2 is passed page 2 is shows and $paged value is 2.

With the rewrite rule in place, if you have over the page numbers you get this:

/brand-list/MyBrand/Mysection/?paged=2

Obviously the rewrite rule is the problem but I'm not sure what part I'm missing.

If I use this url:

/pagename=brand-list&brand=MyBrand&section=MySection&paged=2

with the rewrite all it results in:

/page/2/pagename=brand-list&brand=MyBrand&section=MySection

and works! but my url structure is incorrect.

----- edit ------

my current function

function rewrite_rule_brands() {
        global $wp_rewrite;
        add_rewrite_tag('%brand%','([^/]*)');
        add_rewrite_tag('%section%','([^/]*)');
        add_rewrite_rule('^brand-list/([^/]*)/([^/]*)/page/([0-9]+)?','index.php?pagename=brand-list&brand=$matches[1]&section=$matches[2]&paged=$matches[3]','top');
        add_rewrite_rule('^brand-list/([^/]*)/([^/]*)/?','index.php?pagename=brand-list&brand=$matches[1]&section=$matches[2]','top');
        $wp_rewrite->flush_rules();
    }
    add_action( 'init', 'rewrite_rule_brands' ); 
share|improve this question
    
What order have you got these rules in? You should have your second rule the paged one first and then the other one second. –  Mark Davidson Aug 1 '13 at 22:19
    
I got the same results... added an edit that shows my current function as is. –  dcp3450 Aug 1 '13 at 22:24

2 Answers 2

I changed:

add_rewrite_rule('^brand-list/([^/]*)/([^/]*)/page/([0-9]+)?','index.php?pagename=brand-list&brand=$matches[1]&section=$matches[2]&paged=$matches[3]','top');

to:

add_rewrite_rule('^brand-list/([^/]*)/([^/]*)/page/?([0-9]{1,})/?$','index.php?pagename=brand-list&brand=$matches[1]&section=$matches[2]&paged=$matches[3]','top');

Note the difference is /page/([0-9]+)? is now /page/?([0-9]{1,})/?$

seems to be working now.

share|improve this answer

This answer helped me thru a custom rewrite issue. I want to add that my case was a bit different in that I nested the category tree within the url structure
example.com/brand-list/brand-child-category/brand-grand-child-category/page/1 This would be like brand-list/nike/air-jordans/high-tops/postname

To get mine to work I had 1 call for the categories, then page, and finally the page number qualifier.

$newRules['brand-list/(.+)/page/?([0-9]{1,})/?$'] =
    'index.php?brand=$matches[1]&paged=$matches[2]';

NOTE: my rewrite coding is different but the basic structure could help others.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.