Support » Plugins » Hacks » $wp_rewrite and $wp_query

  • Resolved GabrielCol



    I have this problem with including a query var in wp_query. I’m using the rewrite rules for it, and in the $wp_rewrite that variable exist:

    [products-page/example-cat/(.+?)/?$] => index.php?pagename=products-page&category_id=22&selected_brand=name-of-the-brand

    however when I access mysiteurl/products-page/example-cat/name-of-the-brand/ the variable don’t apear in wp_query.

    This code should insert it:

    function wpsc_query_vars($vars) {
      $vars[] = "selected_brand";
      return $vars;
    add_filter('query_vars', 'wpsc_query_vars');

    But is not doing it.

    Any idea what i’m doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    The query won’t get populated until at least the init action, so if you’re checking for it earlier than that, it won’t be there.

    Make sure you wait until init to look inside the query or to call upon get_query_var().

    Hi Otto, thanks for the reply.

    However this is not the problem, i check the var after the init…any other idea?

    nevermind, i was checking if it’s set by looking in to the $wp_query object, but seems like get_query_var() is getting the value 🙂

    Hi GabrielCol, I need some help if you don’t mind.

    What code are you using for your rewrite and where are you putting it?

    I need the following rewrite condition:
    insurance-leads-types/auto-insurance-leads/([^/]+)/?$’ => ‘index.php?pagename=auto-insurance-leads&state=$matches[2]

    I put this in wp_settings.php before “do_action( ‘init’ );” and the page redirects to the pagename root >> /insurance-leads-types/auto-insurance-leads/.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘$wp_rewrite and $wp_query’ is closed to new replies.