Skip to main content
Bumped by Community user
added 597 characters in body
Source Link
dcp3450
  • 465
  • 3
  • 12
  • 24

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' ); 

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.

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' ); 
Formatted code to be a bit more readable.
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

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"/pagename=brand-list&brand=MyBrand&section=MySection ends up like this, "/brand-list/MyBrand/Mysection"/brand-list/MyBrand/Mysection

However, when using pagination the page number is never returned to wordpress so $paged$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"/pagename=brand-list&brand=MyBrand&section=MySection&paged=2, ends up like this, "/brand-list/MyBrand/Mysection/page/2"/brand-list/MyBrand/Mysection/page/2 but still shows page 1. Checking the $paged$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"/pagename=brand-list&brand=MyBrand&section=MySection&paged=2 is passed page 2 is shows and $paged$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

/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

/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

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

and works! but my url structure is incorrect.

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.

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.

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.

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.

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.

added 237 characters in body
Source Link
dcp3450
  • 465
  • 3
  • 12
  • 24
Loading
Source Link
dcp3450
  • 465
  • 3
  • 12
  • 24
Loading