简体   繁体   English

从WordPress主题/插件更改自定义帖子的永久链接

[英]change permalink of custom-post from wordpress theme / plugin

I purchased a wordpress theme, which came with custom plugin, that allows custom posts, which is titled 'tour'. 我购买了一个wordpress主题,该主题带有自定义插件,该主题允许自定义帖子,标题为“游览”。

The permalink to view the custom post currently is site.com/tour/post-name 当前查看自定义帖子的永久链接是site.com/tour/post-name

I am trying to change the /tour/ so I have updated all the code in the files of the plugin folder from 'tour' to 'visa'. 我正在尝试更改/ tour /,因此我已将插件文件夹文件中的所有代码从“ tour”更新为“ visa”。

I also went to my database and changed all my posts from wp_posts and updated the post_type from tour to visa . 我也进入数据库,将所有帖子从wp_posts更改,并将post_type从tour更改为visa

Now the custom posts show in my posts section as it should, but when i go to mysite.com/visa/post-name it goes to my 404 page. 现在,自定义帖子会按原样显示在我的帖子部分,但是当我转到mysite.com/visa/post-name时,它将转到我的404页。

Am i missing something? 我想念什么吗? do i need to change anything else? 我还需要更改其他内容吗?

thanks 谢谢

Check your .htaccess files, in the plugin and in your site root. 在插件和站点根目录中检查您的.htaccess文件。 The theme may have rewrite rules that need to be changed. 主题可能具有需要更改的重写规则。

If the plugin has a built in post type using rewrite in the arguments, I wouldn't recommend overwriting it in the plugin files because if they push out an update to it, it will overwrite your changes. 如果插件具有在参数中使用rewrite的内置发布类型,则我不建议在插件文件中覆盖它,因为如果他们向其推送更新,它将覆盖您的更改。

Your best bet is to overwrite the post type arguments with the register_post_type_args filter. 最好的选择是使用register_post_type_args过滤器覆盖发布类型参数。 Note you may need to adjust the priority from 10 , but this should get you started: 请注意,您可能需要从10调整优先级,但这可以帮助您入门:

add_filter( 'register_post_type_args', 'scotty_tour_to_visa', 10, 2 );
function scotty_tour_to_visa( $args, $post_type ){
    if( $post_type == 'tour' ){
        $args['rewrite']['slug'] = 'visa';
    }

    return $args;
}

Also note that I'd recommend rolling back the changes you made, and using the above filter, or add_rewrite_rule() , as what you've done isn't future-proof if there's a security update that comes out for the theme/plugin - and you'll have to redo all/most of what you've done. 还要注意,我建议您回滚所做的更改,并使用上面的过滤器或add_rewrite_rule() ,因为如果主题/插件有安全更新,那么您所做的工作就不会面向未来。 -并且您必须重做所有/大部分已完成的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM