最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - Create and Update 2 CPT sequentially

programmeradmin0浏览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.

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.

Share Improve this question asked Sep 21, 2019 at 17:57 SirLouenSirLouen 857 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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...

发布评论

评论列表(0)

  1. 暂无评论