How to force update all posts after import

There are 2 ways that you could do this. The first and more difficult is to write a program, the other is to do a bulk update. Why do difficult when easy way will work equally well? and especially as this is a once-off requirement

The easy way:

  1. In the admin dashboard, select the view with all posts for your custom type
  2. Select all the posts (tick them) – You can see more posts by clicking ‘Screen Options’ at the top right of the view and increasing the number of items per page
  3. Click the down arrow next to ‘Bulk Actions’ and select edit
  4. Press ‘Apply’ – you will get a screen with a selection of changes you can make
  5. Make some change, like add a tag or change author (whatever)
  6. Press ‘Update’

That should do it.

The ‘difficult’ way:

In case anyone wants to use the code solution, you can add the code below to the functions.php file in your child theme.

function my_update_posts() {
    //$myposts = get_posts('showposts=-1');//Retrieve the posts you are targeting
    $args = array(
        'post_type' => 'post',
        'numberposts' => -1
    );
    $myposts = get_posts($args);
    foreach ($myposts as $mypost){
        $mypost->post_title = $mypost->post_title.'';
        wp_update_post( $mypost );
    }
}
add_action( 'wp_loaded', 'my_update_posts' );

Remember to run this only once and then remove it or comment out the add_action line otherwise it will run every time a new page is loaded.

I included this option in case anyone wants a start template for updating all post titles or some other property in all posts.

Leave a Comment