批量修改wordpress内容的代码


include_once('../wp-load.php');
$t = ($_REQUEST['page'])?(int)$_REQUEST['page']:1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 500,
'paged' => $t,
);
global $wp_query;
$wp_query = new WP_Query( $args );
while ( have_posts() ) {
the_post();
$table = get_the_content();
$table = unserialize($table);
array_walk($table,function(&$value,$key){
$value = preg_replace('/ ?/', ' ', $value);
$value = str_ireplace('', $value);
$value = str_ireplace('>>', '>', $value);
$value = str_ireplace('
', '
', $value);
});
$post = array(
'ID' => get_the_ID(),
'post_content' => serialize($table),
'tags_input' => analysis_keyword((preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $table['标题'].$table['标题'].$table['标题'].$table['内容'].$table['回复'].$table['地点'], $matches)?implode('', $matches[0]):'')),
);
kses_remove_filters();
$post_id = wp_update_post( $post,$wp_error);
kses_init_filters();
}
$t++;
if($t < $wp_query->max_num_pages){
$url = "http://www.yaoruisheng.com/somewhere/modify.php?page=" . $t ;
header( 'refresh:3;url='.$url );
echo 'You\'ll be redirected in about 3 secs. If not, click here.';
} else {
echo 'done!';
}