我搜索并看到了几个类似的问题,但没有一个有用的答案。 我有一个插件,可以自动将格式分配为url
website.com\event\this-is-the-post-title
即使我更改了永久链接结构,插件也不会遵循它,并且我希望具有以下格式(在标题前添加帖子ID),因为我希望多个帖子具有相同的标题(它们是事件)>
website.com\event\1234-this-is-the-post-title
如何自动添加帖子ID? 我还需要url重写功能吗?
谢谢
答案 0 :(得分:0)
add_filter('init', 'custom_perma_link');
function custom_perma_link(){
global $wp_rewrite;
//Write the rule
$wp_rewrite->set_permalink_structure('/%post_id%-%postname%/');
//Set the option
update_option( "rewrite_rules", FALSE );
//Flush the rules and tell it to write htaccess
if(is_admin())
$wp_rewrite->flush_rules( true );
}
尝试此代码