批量修改 wordpress 标题 和对应的 slug (post_title,post_name): sanitize_title($title);生成slug

来源:互联网 发布:淘宝卫龙旗舰店 编辑:程序博客网 时间:2024/06/05 01:05
<?php//----------------------------------------------------------- global $current_user;if ($current_user->ID === 1) {global $wpdb;$sql = "select ID, post_title title,post_name name from {$wpdb->prefix}posts where post_type='topic' and post_title like '%'";$rs = $wpdb->get_results($sql);//echo "<pre>".print_r($rs,true)."</pre>";foreach($rs as $value){$id = $value->ID;$title = $value->title;echo $title."<br>";//$title = str_replace('My','Postal Status of',$title);//$title = str_replace('number is','number',$title);//$title = str_replace('. Any information about the package status?','',$title);$title = str_replace('The tracking number of my package is','Postal Status of India Post Speed Post Tracking number',$title);$name = sanitize_title($title);//echo $value->title."<br>".$title."<br>".$name."<br><br>";$sql2 = "update {$wpdb->prefix}posts set post_title='{$title}', post_name='{$name}' where ID={$id} ";//echo $sql2."<br>";//$flag = $wpdb->query($sql2);}//echo "PS:Update ".$flag." records!!!";}?>

0 0