Correct usage of add_rewrite in plugin
-
Following this post
http://ww.wp.xz.cn/support/topic/208830?replies=6
I came up with this code:function wftp_rewrite() { global $wp_rewrite; $wp_rewrite->flush_rules(); add_rewrite_rule('wftp/([^/]+)/?$', 'index.php?wftp=$matches[1]','top'); } function wftp_vars($public_query_vars) { $public_query_vars[] = 'wftp'; return $public_query_vars; } add_filter('query_vars', 'wftp_vars'); add_action('init', 'wftp_rewrite');But that doesn’t work. However, based on this post http://codex.ww.wp.xz.cn/Custom_Queries, the following does work:
function wftp_flush_rewrite() { global $wp_rewrite; $wp_rewrite->flush_rules(); } function wftp_vars($public_query_vars) { $public_query_vars[] = 'wftp'; return $public_query_vars; } function wftp_add_rewrite_rules($wp_rewrite) { $new_rules = array( 'wftp/(.+)' => 'index.php?wftp=' . $wp_rewrite->preg_index(1)); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_action('init', 'wftp_flush_rewrite'); add_filter('query_vars', 'wftp_vars'); add_action('generate_rewrite_rules', 'wftp_add_rewrite_rules'); add_action('parse_query', 'wftp_init');Can anyone explain to me why I can’t use add_rewrite_rule in this way, since it seems like it works in this post:
http://danmarvelo.us/older/2007/5/30/custom-rewrite-wordpress-add_rewrite_rule-add_rewrite_tag/I don’t understand why I have to add directly to $wp_rewrite…
Thanks for your help!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Correct usage of add_rewrite in plugin’ is closed to new replies.