add_rewrite_rule permalinks break in WordPress 4.5
add_rewrite_rule permalinks break in WordPress 4.5
add_rewrite_rule permalinks break in WordPress 4.5
Get query parameters from external url and make a redirection
add_filter(‘query_vars’) not working in custom template
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; }