Last active
July 25, 2017 19:04
-
-
Save nicknmejia/3c4bb55d289ce7643e331cc02ca7be78 to your computer and use it in GitHub Desktop.
Affiliate Migration
This file contains hidden or 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 | |
ini_set('xdebug.max_nesting_level', 10000); | |
// Setup Wordpress Environment for Migration Script | |
setup(); | |
global $wpdb; | |
$query = '[simpleazon-link'; | |
$query_arr = $wpdb->get_results( | |
" | |
SELECT ID,post_title, post_content | |
FROM $wpdb->posts | |
WHERE post_content LIKE '%$query%' AND post_status = 'publish' | |
" | |
); | |
foreach ( array_filter( $query_arr ) as $q ) { | |
$content = $q->post_content; | |
$converted_string = preg_replace('/\[simpleazon(.*?)\]/', '', $content); | |
$converted_string_2 = preg_replace('/\[\/simpleazon(.*?)\]/', '', $converted_string); | |
$updated_post = array( | |
'ID' => $q->ID, | |
'post_content' => $converted_string_2, | |
); | |
wp_update_post($updated_post); | |
} | |
echo "All done!"; | |
function setup() { | |
define('WP_USE_THEMES', false); | |
if ( !defined('ABSPATH') ) { | |
/** Set up WordPress environment */ | |
require_once( dirname( __FILE__ ) . '/wp-load.php' ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment