0

Is there a way to cycle through all existing, published posts on a WP site, that will replicate pushing the "update" button on every post one by one? This would be a one time event. I have a site with thousands of existing posts and there is no way I can go through and hit "update" on every single one of them.

I've added a plugin that will display some new info on each post, but in order for it to work on existing posts, you have to "update" every single post individually.

Thanks

3
  • What do you mean actually you want to change something in all post? Jul 3, 2014 at 5:13
  • It sounds like you should be filtering the post content using the post_content filter, rather than actually updating the post content. If I installed a plugin and it went and edited every one of my posts I wouldn't be happy. Also, cycling through every post on the site is potentially a slow process and is very likely to time out on large sites or on shared hosts. Jul 3, 2014 at 9:19
  • You can also update all posts via Admin area if your server have the power to list them all. List all post, change settings of listing post to a value that list all of your post. Now select all via the checkboxes on the left side and update all posts.
    – bueltge
    Jan 16, 2019 at 11:47

1 Answer 1

0

I'm not sure if it will work, but you could try running wp_update_post() on all posts concerned. It will trigger the save_post hook.

According to the Codex:

Unlike wp_insert_post(), it is only necessary to pass the ID of the post to be updated and the elements to be updated.

You could try looping an array of post IDs and running the function on them. You can fetch the post IDs using WP_Query.

foreach( $posts_id as $post_id ){
    wp_update_post( $post_id );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.