duan3019 2015-04-03 19:32 采纳率: 100%
浏览 62

通过SQL更新多个帖子的wordpress标签

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:

<?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!

  • 写回答

1条回答 默认 最新

  • dth54864 2015-04-03 20:00
    关注
    $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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么