<?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();
} );
根据我们的讨论,我相信在PHP和MySQL上用代码动态覆盖内容的强度会降低,我会这样做:
<?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 );
} );