Last active
February 1, 2023 03:36
-
-
Save dlh01/32e7e46f98e368711e8b62b791725e2c to your computer and use it in GitHub Desktop.
WP Bulk Task example
This file contains 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 | |
( new \Alley\WP_Bulk_Task\Bulk_Task( 'bananaify' ) )->run( | |
[ | |
'post_status' => 'publish', | |
], | |
function ( $post ) { | |
if ( str_contains( $post->post_content, 'apple' ) ) { | |
$new_value = str_replace( 'apple', 'banana', $post->post_content ); | |
if ( ! empty( $assoc_args['dry-run'] ) ) { | |
\WP_CLI::log( 'Old post_content: ' . $post->post_content ); | |
\WP_CLI::log( 'New post_content: ' . $new_value ); | |
} else { | |
$post->post_content = $new_value; | |
wp_update_post( $post ); | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment