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?
1 Answer
Reset to default 0There'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.