2014-02-12 33 views
0

我使用的是從我的插件的設置來產生重寫規則:爲什麼wordpress不能在我的插件中識別add_rewrite_rule?

$bioPage = $wpdb->get_var("SELECT settingValue FROM $table_name WHERE settingType='bioPage'"); 
$post = get_post($bioPage); 
$slug = $post->post_name; 

add_rewrite_tag('%player%','([^&]+)'); 

add_rewrite_rule('^'.$slug.'/([^/]*)$','/'.$slug.'/?player=$matches[1]','top'); 

我得到正確的蛞蝓。

我有一個網址,看起來像這樣:

mysite.com/info/?player=joe.smith.01 

我希望它看起來像這樣:

mysiste.com/info/joe.smith.01 

我使用的是add_rewrite_tag所以WP將抓住該URL的變量。當我訪問一個結構像我試圖實現的頁面url時,我找不到一個頁面。

+0

你修改htaccess文件?直接嘗試 –

+0

我會,但我需要使用插件來改變重寫,因爲htaccess生活在主題文件之外。 – dcp3450

回答

0

我不會推薦修改htaccess文件,如果你沒有必要。 WP的重寫APi應該沒問題。

這就是說,我敢肯定你必須通過add_rewrite_rule()的rewrite參數中的'index.php'去。

我沒有現在正在測試這一權利的任何方式,而是沿着以下線的東西可能工作:

$bioPage = $wpdb->get_var("SELECT settingValue FROM $table_name WHERE settingType='bioPage'"); 
$post = get_post($bioPage); 
$slug = $post->post_name; 
$page_id = $post->ID; //Get the post ID to include in the page_id query var 

add_rewrite_tag('%player%','([^&]+)'); 
add_rewrite_rule('^'.$slug.'/([^/]*)$','index.php?page_id='.$page_id'.&player=$matches[1]','top'); 
相關問題