Flush_rewrite_rules not working when settings updated

Does this work for you? Seems to work when I try it. function qd_settings_api_init() { add_settings_section( ‘qd_theme_setting_section’, ‘Theme Reading Settings’, ‘qd_theme_setting_section_callback_function’, ‘reading’ ); add_settings_field( ‘qd_news_page’, ‘News Page’, ‘qd_news_page_dropdown_cbf’, ‘reading’, ‘qd_theme_setting_section’ ); if (delete_transient(‘qd_flush_rules’)) flush_rewrite_rules(); // * Added register_setting( ‘reading’, ‘qd_news_page’, ‘qd_sanitize’ ); // * Changed } /* Added this function. */ function qd_sanitize($input) { set_transient(‘qd_flush_rules’); … Read more

Custom post types and custom variables — add_rewrite_tag() question

function add_places_rewrite_tags() { add_rewrite_tag(‘%action%’,'([^&]+)’); } add_action( ‘init’, ‘add_places_rewrite_tags’ ); First add the rewrite tag action (action=xxxx) function add_places_rewrite_rules() { add_rewrite_rule(‘^area/([^/]*)/places/?’,’index.php?post_type=area&name=$matches[1]&action=places’,’top’); add_rewrite_rule(‘^area/([^/]*)/([^/]*)/places/?’,’index.php?post_type=area&name=$matches[2]&action=places’,’top’); } add_action( ‘init’, ‘add_places_rewrite_rules’ ); Then add a custom rewrite rule. (post_type=area may be different if you made a custom slug for the posttype, use the posttype name). Remember to flush your rewrite rules … Read more

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

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

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