0

Is it possible to create + update a CPT after a post have been created sequentially in the same flow?

For example:

First: I do a wp_insert_post($my_first_cpt) (with some data, and it's executed on save_post hook)

Second: wp_update_post($my_second_cpt) (with DATA from $my_first_cpt, for example a random seed) and show be executed inmediately after

So essentially $my_first_cpt has to be created and stored and inmediately afterwards, something has to fire to get data from $my_first_post and update $my_second_post

Is this possible? I've tried to put one after another and it doesn't simply work.

1 Answer 1

0

I've found a solution, which I'm not liking much, but it works

Essentially what I do is create two hooks to save_post (in this case this is the action that launches this script) with different priorities for example 10 and 20 In the priority 10 I put the wp_insert_post And in the priority 20 I put the wp_update_post

It works, but is doesn't seem to be the best solution...

Your Answer

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

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