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
?
1 Answer
Reset to default 1While 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
评论列表(0条)