Saturday, November 5, 2022
HomeWordPress Developmentdatabase - Bulk set Put up Title as Tag the place Tag...

database – Bulk set Put up Title as Tag the place Tag is Empty Perform


I’m utilizing the next operate to set the Title as Tag for every of my printed posts. Sadly it doesn’t work with over 20K+ Pages -> Timeout.

My answer could be limiting the posts_per_page to 1000 and run the question a number of occasions on posts the place the tag is empty.

Any thought how one can examine if the tag is empty? Or every other thought how one can repair this situation. THX

add_action( 'init', 'default_function' );
operate default_function() {

    if ( is_admin() ) { 
    
        $args = array(
            'posts_per_page'   => 1000,
            'offset'           => 0,
            'class'         => '',
            'category_name'    => '',
            'orderby'          => 'date',
            'order'            => 'DESC',
            'embrace'          => '',
            'exclude'          => '',
            'meta_key'         => '',
            'meta_value'       => '',
            'post_type'        => 'submit',
            'post_mime_type'   => '',
            'post_parent'      => '',
            'writer'       => '',
            'author_name'      => '',
            'post_status'      => 'publish',
            'suppress_filters' => true
        );
        $posts_array = get_posts( $args );

        foreach ($posts_array as $current_post) {

            $post_id = $current_post->ID;
            $post_title = $current_post->post_title;

            wp_set_post_tags( $post_id, $post_title, true );

        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments