Connect custom rewrite rules and query variables to wordpress navigation
Connect custom rewrite rules and query variables to wordpress navigation
Connect custom rewrite rules and query variables to wordpress navigation
I think the add_rewrite_rule is the correct route to go and I think what you have is correct also barring the Regex. Try substituting what you have currently for this => ^my-page\/([0-9]+)\/?. Full code below: function setup_filter_rewrites(){ add_rewrite_rule(‘^my-page\/([0-9]+)\/?’, ‘index.php?pagename=my-page&my_var=$matches[1]’, ‘top’); } add_action( ‘init’, ‘setup_filter_rewrites’ );
[] = not [] .= to append to an array. function custom_query_vars_filter($vars) { $vars[] = ‘ae_issues’; $vars[] = ‘issueloc’; $vars[] = ‘issuearea’; return $vars; } Another trick, if you don’t want to mess with a query is to change these vars to something like _issueloc & _issuearea. I found making custom queries as flags is … Read more
How to redirect a query string to a “virtual” subdirectory
The simplest way is done right in the post editor, you can use the button that is second in from the right side, of the editor toolbar, to insert a read more link at a certain point in your post. WordPress will display a shortened post with a read more link when the post is … Read more
Here is my current code: function hm_base_date_query_vars($vars) { $vars[] = ‘base_date’; return $vars; } add_filter(‘query_vars’, ‘hm_base_date_query_vars’); function hm_base_date_rewrite_rule() { add_rewrite_rule( ‘^my-calendar/([^/]*)/?’, ‘index.php?pagename=my-calendar&base_date=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘hm_base_date_rewrite_rule’, 10, 0); $base_date_test = get_query_var(‘base_date’); on the url example.com/my-calendar/foo my var $base_date_test returns null Maybe someone can help me. Thanks. // Edit: It works. I tried to call … Read more
You can filter request and unset m there, which will remove it from the query. This is a simple example that will remove it in all cases, you probably want to narrow the check down with something else, like checking if pagename is also set: function wpd_request_filter( $request ){ if( isset( $request[‘m’] ) ){ unset( … Read more
I would think that .com/genre/comedy is actually picked up by the second rule since it matches that as well, and because it is added first I think it takes precedence. You could try to swap the order, so it goes 3, 4, 1, 2. For production, you might want to remove flush_rewrite_rules();, I believe it’s … Read more
Own query vars are not displayed
WP CLI – Pass Query / URL Variable to Cron?