Bulk updates to post_content
<?php
/**
* Plugin Name: Bulk Post Update
* Version: 1.0.0
*
* @author Nabil Kadimi <[email protected]>
* $link http://wordpress.stackexchange.com/a/242499/17187
**/
add_action( 'init', function() {
global $wpdb;
$table = $wpdb->posts;
$post_type="custompost";
$new_post_content="Text I want to update all my post content to";
$affected = $wpdb->query(
$wpdb->prepare( "UPDATE {$table} SET post_content = %s, WHERE post_type = %s"
, $new_post_content
, $post_type
)
);
echo $affected . ' rows modified, please disable code.' . "\n";
echo 'File: ' . __FILE__ . "\n";
echo 'Line: ' . __LINE__ . "\n";
die();
} );
Edit
Based on our discussion, I believe overriding content on the fly with code will be less intensive on PHP and MySQL, here is how I would do it:
<?php
/**
* Plugin Name: Override Post Content
* Version: 1.0.0
*
* @author Nabil Kadimi <[email protected]>
* $link http://wordpress.stackexchange.com/a/242499/17187
**/
add_filter( 'the_content', function( $content ) {
global $post;
$custom text="blah [blah]";
/**
* Ignore other post types.
*/
if ( 'custompost' !== $post->post_type ) {
return $content;
}
/**
* Return the value I want to override with.
*/
return do_shortcode( $custom_text );
} );