Updating wordpress tags for multiple posts via SQL

Here’s what I want to do:

  1. Find 10 posts that do not have any tags and whose comment count = 0
  2. Tag those 10 posts with a tag “tag_name”

With query_posts, the first part should look something like this I think:

Read More
<?php
query_posts(array(
    'post_type' => 'post',
    'tag' => "",
    'paged' => $paged,
    'comment_count' => '0',
    'posts_per_page' => '10',
)); ?>

I have no idea what the second part should look like, but I think the whole thing needs to be in SQL form in order to be able to update the tags for the found posts.

Any help would be much appreciated!

Related posts

Leave a Reply

1 comment

  1. $tag_name = 'your tag';
    
    $posts = new WP_Query( array(
        'post_type' => 'post',
        'paged' => $paged,
        'comment_count' => '0',
        'posts_per_page' => '10',
    ));
    
    if( $posts->have_posts() ): while( $posts->have_posts() ): $posts->the_post();
    
        wp_set_post_tags( $post->ID, $tag_name );
    
    endwhile; endif; wp_reset_query();