SergeyBiryukov

Sergey Biryukov

Jan 22nd, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2. include 'wp-load.php';
  3. $posts = get_posts('numberposts=-1');
  4. foreach ( $posts as $post ) {
  5.     preg_match('/(.*) ([0-9]{4})/', $post->post_title, $matches);
  6.     if ( !empty($matches) ) {
  7.         echo "Post #{$post->ID}<br />\n";
  8.  
  9.         echo "Title: {$matches[1]}<br />\n";
  10.         $post->post_title = $matches[1];
  11.         wp_update_post($post);
  12.  
  13.         echo "Year: {$matches[2]}<br />\n";
  14.         add_post_meta($post->ID, 'year', $matches[2], true);
  15.     }
  16. }
  17. echo 'All Done!';
  18. ?>
Add Comment
Please, Sign In to add comment