How to check if a rewrite rule exists

If I understand correctly then you can hook into the rewrite api/process and flush or manipulate the rules that way? Read: Plugin Hooks on this page http://codex.wordpress.org/Function_Reference/WP_Rewrite Maybe something like: // flush_rules() if our rules are not yet included function my_flush_rules() { $rules = get_option( ‘rewrite_rules’ ); if ( ! isset( $rules[‘(project)/(\d*)$’] ) ) { … Read more

add_rewrite_rule() vs $wp_rewrite->rules vs ‘rewrite_rules_array’?

First of all use add_rewrite_rule() over messing directly with $wp_rewrite->rules if possible. The latter is a bit low-level. Regarding the ‘url not updating’ – this isn’t the job of the rewrite rules. These simply point urls to their content, but they don’t update the user’s address bar. The file that is responsible for this is … Read more

Why does everybody hook add_rewrite_rule on init

You are right saying that without flushing rules, add_rewrite_rule() does not work, and the reason is that WordPress fetches rules from database, and add_rewrite_rule() does not add the rule to database. However, is not possible to use admin_init and the reason is that admin_init is too late. WordPress sometimes calls flush_rewrite_rules() on admin screens before … Read more

When should add_rewrite_tag() be used?

The fundamental difference is: The add_rewrite_rule() adds a particular rule which is interpreted The add_rewrite_tag() adds a placeholder to use in url structures. This placeholder is then used to generate multiple rules. For instance – suppose you’re a travel agent advertising hotels in various countries. You may want a hotel’s url to be like www.example.com/hotels/UK/Balmoral … Read more