Custom taxonomy rewrite with query var returns %2F in URL
Custom taxonomy rewrite with query var returns %2F in URL
Custom taxonomy rewrite with query var returns %2F in URL
Redirect Uploads Folder to Query Vars in WordPress
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
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
Answered thanks to Milo’s comment. I wrote a small function to check if the query variable exists. Note that get_query_var(‘listen’) didn’t work for me. function is_listen() { $vars = $GLOBALS[‘wp_query’]->query_vars; if ( array_key_exists(‘listen’, $vars) ) { return true; } else { return false; } } Use it in a conditional like so: if ( is_listen() … Read more
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
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; }
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
The p query var expects a post ID, use name instead. Also note that rules should only be flushed when they change, as it’s a computationally expensive operation. It’s best to do that on theme change or plugin activation, whichever is appropriate for where your code is located. You can also do this by just … Read more
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