Last active
August 29, 2015 14:07
-
-
Save caercam/8ea93d1f97c4999f1bc1 to your computer and use it in GitHub Desktop.
Restore all movie titles including movie date to simple movie title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Restore all movie titles including movie date to simple movie title. | |
* | |
* @package WordPress | |
*/ | |
require( dirname( __FILE__ ) . '/wp-blog-header.php' ); | |
$query = new WP_Query( | |
array( | |
'post_type' => 'movie', | |
'posts_per_page' => -1 | |
) | |
); | |
if ( $query->have_posts() ) : | |
while ( $query->have_posts() ) : | |
$query->the_post(); | |
$meta = get_post_meta( $post->ID, '_wpml_movie_data', $single = true ); | |
if ( isset( $meta['meta']['release_date'] ) && '' != $meta['meta']['release_date'] ) : | |
$date = $meta['meta']['release_date']; | |
$date = date_i18n( 'Y', strtotime( $date ) ); | |
// Make sure this movie has been updated before | |
if ( " ($date)" == substr( $post->post_title, -7 ) ) : | |
$post->post_title = substr( $post->post_title, 0, -7 ); | |
$update = wp_update_post( $post, $wp_error = true ); | |
if ( is_wp_error( $update ) ) | |
printf( '"%s": %s<br />', $post->post_title, $update->get_error_message() ); | |
else | |
printf( '"%s" update successfully!<br />', $post->post_title ); | |
endif; | |
endif; | |
endwhile; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment