WordPress - Update all existing posts at once

admin2025-01-07  4

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

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

Share Improve this question edited Jan 16, 2019 at 11:48 bueltge 17.1k7 gold badges61 silver badges97 bronze badges asked Jul 3, 2014 at 4:52 user33991user33991 212 bronze badges 3
  • What do you mean actually you want to change something in all post? – Sudeep Acharya Commented 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. – John Blackbourn Commented 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 Commented Jan 16, 2019 at 11:47
Add a comment  | 

1 Answer 1

Reset to default 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 );
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736263692a911.html

最新回复(0)