Rewriting permalinks with custom posts
Oh dear, turns out I need to touch up on my regex, the second match only matches one character. It ought to be: ‘([\w]{2})/the-wines/([^/]+)/?’ => ‘index.php?pagename=$matches[2]&lang=$matches[1]’
Oh dear, turns out I need to touch up on my regex, the second match only matches one character. It ought to be: ‘([\w]{2})/the-wines/([^/]+)/?’ => ‘index.php?pagename=$matches[2]&lang=$matches[1]’
This is why you need to add rewrite rules on the init action on every request, as well as on plugin activation. When your plugin deactivation hook is run, other plugin init hooks have already run, so their rules exist in the global variable that stores them for the life of each request. Flushing rewrite … Read more
Found the solution in this thread: How to prevent the default home rewrite to a static page Just disable canonical redirect for front page: function disable_canonical_redirect_for_front_page( $redirect ) { if ( is_page() && $front_page = get_option( ‘page_on_front’ ) ) { if ( is_page( $front_page ) ) $redirect = false; } return $redirect; } add_filter( ‘redirect_canonical’, … Read more
Rewrite rules don’t call functions like you’re asking. WordPress is far more flexible than that, because you might want to run your code at any one of an unlimited set of points in the processing of the page and not be restricted to that one specific moment in the code when the rewrite rule is … Read more
When you point a rule to anything other than index.php, it gets interpreted as external and written to the .htaccess file. After external rules are parsed, requests get directed to WordPress, which parses the internal rules in php. This is the internal version: function custom_rewrite() { add_rewrite_rule( ‘^(bar|baz|foo-.*)’, ‘index.php?my_var=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite’ … Read more
There are a few things to sort out here. The first is why your rewrite rule will not work. add_rewrite_rule(‘/api’, ‘/wp-admin/admin-ajax.php’, ‘top’); The WordPress rewrite does not redirect to a page. What does is it parses the path using regular expressions into a WordPress query vars. If you disable pretty URLs in WordPress, you’ll see … Read more
Conditional variables are based on the main page query ($wp_query). If you want is_home() to be false, then you need to manually set it to false ($wp_query->is_home = false) or override the main query such that it’s not true anymore. Probably you’d do that in your template_redirect_intercept function there, or in the individual page templates … Read more
The 404 might be created because your regular expression requires the value after ‘state/’. Please try to replace: function handle_taxonomy_route() { add_rewrite_rule(‘^state/([^/]+)/?’, ‘index.php?state_var=$matches[1]’, ‘top’); } with: function handle_taxonomy_route() { add_rewrite_rule(‘^state/([^/]*)/?’, ‘index.php?state_var=$matches[1]’, ‘top’); }
Take a look at the “Template Hierarchy” Codex page. Custom Post Type Archive display Template file used to render the Archive Index page for a Custom Post Type. [emphasis added] By my reading, that means that the archive-{cpt_slug}.php template is only used for the page that, by default, lists all posts of that post type … Read more
.htaccess Rewrite URL WordPress