通过SQL更新多篇文章的wordpress标签


Updating wordpress tags for multiple posts via SQL

以下是我想要做的:

  1. 查找10个没有任何标签且评论数为0的帖子
  2. 用标签"Tag_name"标记这10条帖子

对于query_posts,我认为第一部分应该是这样的:

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

我不知道第二部分应该是什么样子,但我认为整个部分需要是SQL形式,以便能够更新找到的帖子的标签。

任何帮助都将不胜感激!

$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();