我註冊一個新的自定義文章類型有:自定義永久鏈接
register_post_type('abcd_film',
array(
'labels' => array(
'name' => __('Films'),
'singular_name' => __('Film')
),
'description' => 'Manage the Films',
'supports' => array('title', 'editor', 'custom-fields',),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'films'),
)
);
我的WordPress位於(虛擬鏈路):
www.example.com/folder/wordpress/
我的永久鏈接設置爲( 「後名」 選項):
www.example.com/folder/wordpress/%postname%/
不過,我創建了自定義後鍵入「電影」與後名稱爲「蘋果」下一個新的自定義後,該鏈接顯示404未找到文件。該.htaccess
文件是由WordPress &由WordPress的書面當前內容寫爲:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder/wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /folder/wordpress/index.php [L]
</IfModule>
# END WordPress
我是雙phpinfo()
選中,mod_rewrite()
模塊處於「加載的模塊」部分。另外,我嘗試刷新WordPress Admin > General > Permalink > Save Changes
中的固定鏈接設置。
404未找到仍然存在。我還可以做些什麼?
試過如下:
添加
publicly_queryable
與值true
到選項陣列(它不是必需的,因爲public
已經設置爲true
和publicly_queryable
默認值是等於public
的值)add
with_front
with valuetrue
torewrite
sub-array(* this does not required,作爲with_front
默認值是true
)後
register_post_type()
flush_rewrite_rules(false);
添加所有上述的嘗試沒有任何效果。緩存已被禁用&已刷新。
參考問題:
- WordPress Custom Permalink Structure for: Pages, Posts and Custom Post Types
- permalink structure for single-{post-type}.php in wordpress
- WordPress custom post type: Query by id works, by post_name doesn't
你試過把'flush_rewrite_rules(false); '剛纔?另外,如果你改變永久鏈接結構會發生什麼?你有''public_queryable'=> true,' –
添加''public_queryable'=> true'&'flush_rewrite_rules(false);'&清除緩存,404仍未找到... – Raptor
好吧..最後一件事我現在可以想到的是嘗試''rewrite'=> array(「slug」=>「films」,「with_front」=> true),'與其他人合併。大約兩週前我有同樣的問題,但我不記得罪魁禍首是在哪裏。並請將鏈接結構更改的結果發佈到默認頁面。 –