Change the properties of a custom post type after it's been registered?

The specific use case is that I have a CPT added through a plugin, and I'd like it to be hierarchical, but the post

The specific use case is that I have a CPT added through a plugin, and I'd like it to be hierarchical, but the post type options are hardcoded into the plugin.

Is it possible to change the properties of a custom post type after it's been added via register_post_type?

The specific use case is that I have a CPT added through a plugin, and I'd like it to be hierarchical, but the post type options are hardcoded into the plugin.

Is it possible to change the properties of a custom post type after it's been added via register_post_type?

Share Improve this question asked Feb 26, 2014 at 18:57 numbers1311407numbers1311407 1053 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

While it's possible to manipulate CPT data after registration it's not very "clean" and harder for some things.

Specifically for hierarchical setting registration adds it to rewrite right away:

if ( $args->hierarchical )
    add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename=" );
else
    add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" );

So you'll have to redo this really carefully and make sure it survives flushing rewrite rules properly.

Altogether it would be more robust to look into forking or extending that part of plugin in question and just register CPT like you need it to.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745108280a4611688.html

相关推荐

  • Change the properties of a custom post type after it's been registered?

    The specific use case is that I have a CPT added through a plugin, and I'd like it to be hierarchical, but the post

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信