Created
March 27, 2020 15:10
-
-
Save twentyfortysix/a3e74a5b8a453e61bc939ffef1d9fa06 to your computer and use it in GitHub Desktop.
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 | |
function replacer($post_type, $field, $find, $replace, $wet){ | |
$args = array( | |
'post_type' => $post_type, | |
'posts_per_page' => -1, | |
'post_status' => 'any' | |
); | |
$the_query = new WP_Query( $args ); | |
if ($the_query->have_posts()) { | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
$replacement = str_replace($find, $replace, $the_query->post->{$field}); | |
$upsert = array( | |
'ID' => $the_query->post->ID, | |
$field => $replacement | |
); | |
echo $the_query->post->{$field} . ' // ' . $replacement . '<br>'; | |
// Update the post into the database | |
if($wet == true){ | |
wp_update_post( $upsert ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment