admin管理员组

文章数量:1024885

I'm creating a plugin that creates a post in a CPT for every Facebook page post (using fb graph api). When should I fire the function that gets the data? using an action? Also if I understood the docs correctly, the wp_insert_post takes ID as an argument, which if doesn't exist, sets the newly created post id to that value?

I'm creating a plugin that creates a post in a CPT for every Facebook page post (using fb graph api). When should I fire the function that gets the data? using an action? Also if I understood the docs correctly, the wp_insert_post takes ID as an argument, which if doesn't exist, sets the newly created post id to that value?

Share Improve this question edited May 14, 2019 at 12:55 cjbj 15k16 gold badges42 silver badges89 bronze badges asked May 14, 2019 at 12:25 Silvester VellaSilvester Vella 155 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There's no way to get notifications from Facebook for a new post. You have to check by hand. Just set a transient with the desired expire time for the data so you don't make a request on each reload, maybe check hourly for new data or every 30 mins, up to you.

As for your second question, read the docs:

https://developer.wordpress/reference/functions/wp_insert_post/

It automatically assigns an ID unless provided by you (which is auto-incremented by the system) but you still need to provide more things in the array, even if some are default, you might not want it like that.

I'm creating a plugin that creates a post in a CPT for every Facebook page post (using fb graph api). When should I fire the function that gets the data? using an action? Also if I understood the docs correctly, the wp_insert_post takes ID as an argument, which if doesn't exist, sets the newly created post id to that value?

I'm creating a plugin that creates a post in a CPT for every Facebook page post (using fb graph api). When should I fire the function that gets the data? using an action? Also if I understood the docs correctly, the wp_insert_post takes ID as an argument, which if doesn't exist, sets the newly created post id to that value?

Share Improve this question edited May 14, 2019 at 12:55 cjbj 15k16 gold badges42 silver badges89 bronze badges asked May 14, 2019 at 12:25 Silvester VellaSilvester Vella 155 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There's no way to get notifications from Facebook for a new post. You have to check by hand. Just set a transient with the desired expire time for the data so you don't make a request on each reload, maybe check hourly for new data or every 30 mins, up to you.

As for your second question, read the docs:

https://developer.wordpress/reference/functions/wp_insert_post/

It automatically assigns an ID unless provided by you (which is auto-incremented by the system) but you still need to provide more things in the array, even if some are default, you might not want it like that.

本文标签: wp insert postwpinsertpost with data from graph api inside a plugin