Skip to content

Instantly share code, notes, and snippets.

@anisotropy
Last active October 27, 2016 23:58
Show Gist options
  • Save anisotropy/42927ea52aac0c036ae6f5482b7bff02 to your computer and use it in GitHub Desktop.
Save anisotropy/42927ea52aac0c036ae6f5482b7bff02 to your computer and use it in GitHub Desktop.
워드프레스: 특정한 문자열이 포함된 제목을 가진 포스트들을 구하고 그 포스트들의 내용을 변경
<?php
$keyword = 'something';
global $wpdb;
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%keyword%'");
foreach($posts as $p){
$id = $p->ID;
$title = $p->post_title;
$content = $p->post_content;
wp_update_post(array(
'ID' => $id,
'post_title' => 'changed: '.$title,
'post_content' => 'changed: '.$content
));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment