admin管理员组文章数量:1415111
I have created a custom taxonomy, which has 2 terms. I'd like to have both of these checked/selected by default when someone creates a new post. Is this possible? I've searched but found no solutions.
Thank you!
I have created a custom taxonomy, which has 2 terms. I'd like to have both of these checked/selected by default when someone creates a new post. Is this possible? I've searched but found no solutions.
Thank you!
Share Improve this question asked Nov 15, 2014 at 18:52 LBFLBF 5393 gold badges11 silver badges28 bronze badges2 Answers
Reset to default 1There is nothing directly meant for that (that I can think of), but there is very close in purpose function get_default_post_to_edit()
.
Since for the purpose of new post creation it makes post appear in DB before it is even saved for the first time (as auto draft) we can tinker with its filters a bit to make it happen:
add_filter( 'default_content', function ( $content, $post ) {
if ( ! is_admin() ) {
return $content;
}
$screen = get_current_screen();
if ( 'post' === $screen->base && 'add' === $screen->action && 'code-project' === $screen->post_type ) {
wp_set_object_terms( $post->ID, 'plugin', 'code-project-type' );
}
return $content;
}, 10, 2 );
I achieve it for specific Role:
add_filter( 'default_content', function ( $content, $post ) {
if ( current_user_can( 'role_one' ) ){
if ( ! is_admin() ) {
return $content;
}
$screen = get_current_screen();
if ( 'post' === $screen->base && 'add' === $screen->action && 'events' === $screen->post_type ) {
wp_set_object_terms( $post->ID, 'Světu mír', 'přání' );
}
}
return $content;
}, 10, 2 );
本文标签: custom taxonomyCan you precheck wordpress categories
版权声明:本文标题:custom taxonomy - Can you pre-check wordpress categories? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745196810a2647182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论