1

I'm trying to pass a query var with a friendly url to the front page but I just get redirected to the front page without var. I use a static page as the front page.

If I go to example.com/price I want to load the front page with query variable sortorder with value price.

Query var i in functions.php

function test_query_vars( $qvars ) {
  $qvars[] = 'sortorder';
  $qvars[] = 'product';
  return $qvars;
}
add_filter( 'query_vars', 'test_query_vars' );

And rewrite rule below.

function test_rewrite_rule() {

  add_rewrite_rule( '^price/?$', 'index.php?page_id=8&sortorder=price','top' );

}
add_action('init', 'test_rewrite_rule', 10, 0);

The problem is that page_id 8 is my front page so I get redirected to the front page without query var. So if I go to example.com/price I get redirected to example.com. If I change page_id and load another page that is not the front page it works as expected.

  • is your front page a static page or the page for posts? – Milo Jul 23 '18 at 1:35
  • @Milo I use a static page as front page. – ROlf Jul 23 '18 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.