Get post_id in a function which runs once a day?
-
I am creating a plugin for myself which I’ll be using in conjunction with two already published in WP repository.
I am using WP Web Scrapper (https://wordpress.org/plugins/wp-web-scrapper/) to scrape some data from other websites. Now this plugin saves the WP transients API and saves the data for a certain amount of time. However, I want to save the data in a new database table so that I can access it later or manipulate it to create charts and stuff.
Now I want to run the Web Scrapper plugin once or twice every day so it fetches the data and saves it in the database. I dont know much about creating WP plugins but from what I know, you use hooks like wp_head to call your plugin function on every page (let’s say for a plugin which adds a facebook button on your posts).
Since I do not need to call this plugin on every post, I only need to run it once every day? Which hook can I use?
Secondly, when the plugin function is running on every post, you can get the post ID by using the get_the_id() function or WP_post class. How can I get the post ID when the plugin isn’t running on every page? I need the post ID in plugin to retrieve some post meta data which is needed to scrape the data for each post. I am putting this meta data in each using the CMB2 plugin (https://wordpress.org/plugins/cmb2/).
Thanks.
- The topic ‘Get post_id in a function which runs once a day?’ is closed to new replies.