Skip to content

Instantly share code, notes, and snippets.

@nicknmejia
Last active July 25, 2017 19:04
Show Gist options
  • Save nicknmejia/3c4bb55d289ce7643e331cc02ca7be78 to your computer and use it in GitHub Desktop.
Save nicknmejia/3c4bb55d289ce7643e331cc02ca7be78 to your computer and use it in GitHub Desktop.
Affiliate Migration
<?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