Last active
June 27, 2017 06:24
-
-
Save kakoma/21adbfef4696af65238c26705bbd0188 to your computer and use it in GitHub Desktop.
WordPress Plugin to update WordPress posts in bulk, changing any post field, not just the ones WP admin allows. Customize the code inside the foreach loop as desired. Save this in a file, place it in your plugins directory and activate it. The changes will run on activation. Delete the plugin after the change. Article on this here: http://kakoma…
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 | |
/** | |
* Plugin Name: Post Bulk Update | |
* Description: On activation, I'll updates certain fields of your posts at once. Can't wait! | |
* Version: 1.0.0 | |
* Author: Your name here | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* */ | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
if ( ! class_exists( 'MyPlugin_BulkUpdatePosts' ) ) : | |
class MyPlugin_BulkUpdatePosts { | |
public function __construct(){ | |
register_activation_hook( __FILE__, array( $this, 'do_post_bulk_update' ) );//Run this code only on activation | |
} | |
//Put your code in this function | |
public function do_post_bulk_update(){ | |
$posts_to_update = get_posts('cat=x&showposts=1000');//Retrieve the posts you are targeting. CHANGE THIS to retrieve the posts you want to update | |
foreach ( $posts_to_update as $update_this_post ): | |
$update_this_post->post_title = 'Post Prefix: '.$update_this_post->post_title;//The post field you are updating. | |
wp_update_post( $update_this_post ); | |
endforeach; | |
} | |
} | |
endif; | |
return new MyPlugin_BulkUpdatePosts(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment