Custom rewrite_rules – only pass numbers and not alphabetic characters

Instead of index.php/reco/?b=$1, try this: “$wp_rewrite->index?pagename=reco&b=” . $wp_rewrite->preg_index( 1 ) You should also append a $ to your reco/([^/]*)/? regex to ensure the rule only matches the entire path, and not just the beginning. Then flush your rules afterwards (just re-save your permalink settings in admin). Update: Try using the page_rewrite_rules filter instead, and use … Read more

get_query_var not works

Your filter: function add_query_vars_filter( $vars ){ $vars[] = “getvar”; return $vars; } add_filter( ‘query_vars’, ‘add_query_vars_filter’ ); Is correct. When WordPress starts assembling the list of query variables, this function will add ‘getvar’ to the list. But then you immediately check if the variable is set before it reaches that point. The query_vars filter hasn’t happened … Read more

query_vars filter not working even though query string parameter is present

I’m not sure it quite works like that. Try inspecting $query->public_query_vars instead and I think you’ll see it added in there. The way I usually use it is like this: add_filter( ‘query_vars’, ‘add_test_query_vars’); function add_test_query_vars($vars){ $vars[] = “test”; return $vars; } So the same as you but with a named function. Then I add a … Read more

get_query_var not working for subdirectory

You shouldn’t use get_query_var for getting the pagename (slug) – there is no guarantee that pagename will be set, depending on your permalink structure (or lack thereof). Instead, check if the request is for a page, and then get the slug directly from the queried object: if ( is_page() ) { $slug = get_queried_object()->post_name; }

get_query_var returns wrong default value

The default value of get_query_var( $var, $default ) is only returned if the query variable $var isn’t available in the global $wp_query object. The order query variable actually falls back to the DESC value here: if ( ! isset( $q[‘order’] ) ) { $q[‘order’] = $rand ? ” : ‘DESC’; } … within WP_Query::get_posts(), so … Read more

Changing WP_Query params with url Query Var

This code manually sets the order with the ‘order’ => ‘ASC’ declaration in the WP_Query arguments. $loop = new WP_Query( array( ‘post_type’ => ‘product’, ‘meta_key’ => ‘product_price’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘posts_per_page’ => 4, ‘paged’ => $paged) ); If we want to pass a url parameter to that we could use something like: … Read more