custom taxonomy - Can you pre-check wordpress categories?

I have created a custom taxonomy, which has 2 terms. I'd like to have both of these checkedselected by default whe

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 badges
Add a comment  | 

2 Answers 2

Reset to default 1

There 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 );

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

相关推荐

  • custom taxonomy - Can you pre-check wordpress categories?

    I have created a custom taxonomy, which has 2 terms. I'd like to have both of these checkedselected by default whe

    16小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信