Skip Navigation

[Resolved] Is there a way to save all custom post types via a function

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user has a custom code that copy some custom fields from a custom post type to its related posts upon saving. The user looks for a way to do the above for around 9000 posts.

Solution:
A function can be built for this, but I would not recommend so. running this for 9000 posts will definitly hit the server's limits(memory, execution time, etc.). And it would be hard to track what posts were processed correctly and what posts still needs to be processed.

I would suggest doing it manually in batch. Go the custom post type list, change the number of posts per page(20, or 50, or 100) from the screenoptions http://prntscr.com/20xw59i then select all the posts and bulk edit them. Just hit save without changing anything. This will trigger any custom code that is hooked to post_save for those posts.

Based on your server resources, you may run 100s on the same time. You will still need to do it 90 times to complete the 9000 posts.

This support ticket is created 2 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by camila 2 years, 11 months ago.

Assisted by: Jamal.

Author
Posts
#2231149

Hello,
I am wondering if there is a way to save all custom posts via a function? The reason why is that I am using the save post action to copy a field from the parent post, but I can't manually save all posts as I have around 9000 posts.
Any idea how can I accomplish this?
thanks

#2231749

Hello and thank you for contacting the Toolset support.

If I understand well, you want to save the 9000 posts so a custom field can be copied from each post to its parent post in a relationship, right? A function can be built for this, but I would not recommend so. running this for 9000 posts will definitly hit the server's limits(memory, execution time, etc.). And it would be hard to track what posts were processed correctly and what posts still needs to be processed.

I would suggest doing it manually in batch. Go the custom post type list, change the number of posts per page(20, or 50, or 100) from the screenoptions hidden link then select all the posts and bulk edit them. Just hit save without changing anything. This will trigger any custom code that is hooked to post_save for those posts.

Based on your server resources, you may run 100s on the same time. You will still need to do it 90 times to complete the 9000 posts.

Does it make sense? Let me know if you have any further questions.

#2232611

Yes it makes sense, thanks!