分批替换文章内容

以产品内容为例:

$newcontent = str_replace("<strong>Measurements</strong>","<strong>Body Measurements</strong>",$yuan);
$args = array(
  'numberposts' => -1,
  'post_type'   => 'product'
);
$tihuanqian = '<strong>Measurements</strong>';
$tihuanhou = '<strong>Body Measurements</strong>';
$products = get_posts( $args );//718
$i = 0;
foreach ($products as $product){
    $i++;
    if($i >= 0 and $i < 719){
        $yuan =$product->post_content;
        $newcontent = str_replace($tihuanqian,$tihuanhou,$yuan);
        wp_update_post(array(
              'ID'           => $product->ID,//the ID of the Post
              'post_content' => $newcontent,
        ));
    }
    
}
© 版权声明
WWW.ANXKJ.TOP
喜欢就支持一下吧
点赞9 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容