簡體   English   中英

通過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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM