分批替换文章内容

以产品内容为例:

$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,
        ));
    }
    
}
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享