Copy Tags from one post type to another post type

I am using Ultimate member plugin and my client wants to copy all the tags from Ultimate Member plugin (custom post type) to WordPress standard Posts type tags.

Is there any query that I can copy all these? Because there are hundreds of tags that I have to copy and manually it will take much time. So if I will be able to do this with the query then it will save a lot of my time.

1 Answer
1

You didn’t post any code, including the name of custom post type that Ultimate Member is creating, but this is the general query for your request:

function copy_my_tags(){
    // Get every terms used by Ultimate Member
    $terms = get_terms( array(
            'taxonomy' => 'custom_tax',
            'hide_empty' => false,
        ) );
    // Run a loop and create tags based on custom terms
    foreach ($terms as $term) {
        // Check if the tag already exists
        if(!term_exists($term , 'post_tag')){
            wp_insert_term ( array(
                $term,
                'post_tag',
            );
        }
    }
}
add_action('init','copy_my_tags');

Add this code to your theme’s functions.php file, and load any page. Once you load WordPress, the tags will be copied. Then you should delete this code to prevent it from running each time a page is loaded.

Leave a Comment