admin管理员组

文章数量:1406937

In the following code I can set tags automatically and add to a pre-existing category:

<?php function update_post_terms( $post_id ) {
    if ( $parent = wp_is_post_revision( $post_id ) )
        $post_id = $parent;
    $post = get_post( $post_id );
    if ( $post->post_type != 'post' )
        return;

    wp_set_post_terms( $post_id, 'News from, Videos from, Books from', 'post_tag', true );

    wp_set_post_categories( $post_id );
}
add_action( 'wp_insert_post', 'update_post_terms' ); ?>

What I'm trying to do is take 3 tags that will be created automatically, and merge with the category added to the post.

For example: News from, Videos from, Books from (3 predefined tags).

If I create the Technology category, when publishing the tags would be created: News from Technology, Videos from Technology, Books from Technology.

In the following code I can set tags automatically and add to a pre-existing category:

<?php function update_post_terms( $post_id ) {
    if ( $parent = wp_is_post_revision( $post_id ) )
        $post_id = $parent;
    $post = get_post( $post_id );
    if ( $post->post_type != 'post' )
        return;

    wp_set_post_terms( $post_id, 'News from, Videos from, Books from', 'post_tag', true );

    wp_set_post_categories( $post_id );
}
add_action( 'wp_insert_post', 'update_post_terms' ); ?>

What I'm trying to do is take 3 tags that will be created automatically, and merge with the category added to the post.

For example: News from, Videos from, Books from (3 predefined tags).

If I create the Technology category, when publishing the tags would be created: News from Technology, Videos from Technology, Books from Technology.

Share Improve this question edited Oct 25, 2019 at 21:44 BobGCA2 asked Oct 25, 2019 at 20:59 BobGCA2BobGCA2 3171 gold badge6 silver badges17 bronze badges 2
  • 1 How do you connect the post to the Technology category? If every post in category X also has 3 tags of Something from X what's the point of the tags? – Tom J Nowell Commented Oct 25, 2019 at 21:07
  • This is just an example. It could be used, for example, on a quote site. If I create a category with the writer's name, automatic tags would be created such as: Quotes from Thomas Jefferson, Biography from Thomas Jefferson, Works from Thomas Jefferson. – BobGCA2 Commented Oct 25, 2019 at 21:29
Add a comment  | 

1 Answer 1

Reset to default 0

Try to use this plugin https://wordpress/plugins/bulk-edit-categories-tags/

Best regards

本文标签: Automatically create tags and merge with categories