1

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!

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 );
|improve this answer|||||
  • 1
    That worked! Thank you. To clarify for others, in the example above "code-project" is the custom post type and "code-project-type" is the custom taxonomy and "plugin" is the taxonomy term. – LBF Nov 15 '14 at 21:09
0

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 );
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.