Rewrite rules and query for virtual page

You can create a posts archive by just setting post_type=post in your rewrite rule: function custom_archive_rule() { add_rewrite_rule( ‘custom-archive/?’, ‘index.php?post_type=post’, ‘top’ ); } add_action( ‘init’, ‘custom_archive_rule’ ); WordPress will identify this as is_home, so you’ll have to target it in pre_get_posts by the existence of your extra query variables. function custom_arcive_tax( $query ) { if … Read more

add_feed and flush_rewrite_rules

You have to check the existing rewrite rules before you run a flush. If your feed name is test, they are stored under the keys ‘feed/(feed|rdf|rss|rss2|atom|test)/?$’ and ‘(feed|rdf|rss|rss2|atom|test)/?$’. So this should do the trick: add_action( ‘init’, function() { $name=”test”; $registered = FALSE; add_feed( $name, ‘test_feed’ ); $rules = get_option( ‘rewrite_rules’ ); $feeds = array_keys( $rules, … Read more

add_rewrite_rule() not working

You rewrite rule is quite broad and will most likely generate a lot of conflicts. add_action(‘init’, ‘dcc_rewrite_tags’); function dcc_rewrite_tags() { add_rewrite_tag(‘%propref%’, ‘([^&]+)’); } add_action(‘init’, ‘dcc_rewrite_rules’); function dcc_rewrite_rules() { add_rewrite_rule(‘^cottage-details/(.+)/?$’,’index.php?page_id=2&propref=$matches[1]’,’top’); } Then you can access to propref query var like: $propref = get_query_var( ‘propref’ ); And remember to flush the rewrite rules; you can do it … Read more

Multiple values in a rewrite rule, is it possible?

As far I understand, you know are able to have an URL like example.com/recipes/dinner/ or example.com/recipes/lunch/ but now you also want to have an URL like example.com/recipes/dinner-lunch/ that pulls posts from both “dinner” and “lunch” courses. In currents state of WP rewrites this is not possible just with add_rewrite_rule but you also need to use … Read more

resolve /author/ to a page or archive (of all authors) template

If you use code similar to setup the rewrite rules: function ex_rewrite( $wp_rewrite ) { $feed_rules = array( ‘author/?$’ => ‘index.php?author_page=author_page’ ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; return $wp_rewrite; } // refresh/flush permalinks in the dashboard if this is changed in any way add_filter( ‘generate_rewrite_rules’, ‘ex_rewrite’ ); followed by code to add the author_page as … Read more

Using add_rewrite_rule() to redirect to Front Page

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

How to change the matches in add_rewrite_rule

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

Redirect taxonomy to custom template to list terms in taxonomy

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’); }

Separate posts by chapter per rewrite

Since rewrite topics is something requiring tedious testing and time. And it is not something that 1 answer – 1 code complete because it involves many unknown factors from the asker such as how does the post type is created, settings in query_var which affects the query param is there any plugins involved what other … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)