Skip to content

Instantly share code, notes, and snippets.

@D4R4
Last active August 15, 2019 12:35
Show Gist options
  • Save D4R4/9c7165bc49086f7abbc71bb834a7c2ef to your computer and use it in GitHub Desktop.
Save D4R4/9c7165bc49086f7abbc71bb834a7c2ef to your computer and use it in GitHub Desktop.
Handy tool to replace almost any data in wordpress, just put this in yout theme's directory and add a custom page with the template 'script' and go crazy. This one removes anchor links from Content column of post type 'series'.
<?php
/*
Template Name: script
*/
if ( trim($_GET["key"]) == "DKGJWOIGJDLGDFSDF") {
// Create the WP_User_Query object
$args = array(
'post_type' => 'series',
'post_status' => 'publish',
'posts_per_page' => 2000,
‘orderby’ => ‘title’,
‘order’ => ‘ASC’,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo "==== " . get_the_ID() . " ==== " . get_the_Title() . "<br><br>";
$new_cont = get_the_content();
$new_cont = preg_replace('/<\/?a[^>]*>/','',$new_cont);
$my_post = array(
'ID' => get_the_ID(),
'post_content' => $new_cont,
);
// Update the post into the database
wp_update_post( $my_post );
endwhile;
wp_reset_postdata();
}else{
echo "Access denied";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment