WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $wp_rewrite and $wp_query (5 posts)

  1. GabrielCol
    Member
    Posted 3 years ago #

    Hi,

    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?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    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().

  3. GabrielCol
    Member
    Posted 3 years ago #

    Hi Otto, thanks for the reply.

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

  4. GabrielCol
    Member
    Posted 3 years ago #

    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 :)

  5. christopherharden
    Member
    Posted 2 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic