3

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.

3

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.

  • Thank you so much for your answer and help.It saves lot of my time. – wplearner Jun 16 '17 at 2:25

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.