Simple Cronjob Walker
- Create a CPT
cronjob
for your cronjobs. - Add the relevant post meta data (action, last_executed,… and whatever you need)
-
Create a walker function
function my_cronjob_walker() { $args= array( 'post_type' => 'cronjob', 'posts_per_page' => 1, 'meta_key' => 'last_executed' 'orderby' => 'meta_value', ); $cronjob = new WP_Query($args); if ($cronjob->have_posts()) while ($cronjob->have_posts()) { $cronjob->the_post(); // do your cronjob stuff here do_action(get_post_meta(get_the_ID(), 'action', true); update_post_meta(get_the_ID(), 'last_executed', date('c')); } } if ( ! wp_next_scheduled( 'do_cronjob_walker' ) ) { wp_schedule_event( time(), 'hourly', 'do_cronjob_walker' ); } add_action( 'do_cronjob_walker', 'my_cronjob_walker' );
Related Posts:
- WP Cron and wp_insert_post
- WP_QUERY returns empty set when fired from a WP-CRON scheduled event
- Using WP_Query and WP_Meta_Query Outside of WordPress
- cron job for custom post type not working since WordPress 5
- Updating an intensive wp_query result once daily
- Wrote a WP Cron Plugin and it triggers a fatal error upon activation
- How to Insert data with wp cron
- Using a custom WP_Query with get_template_part loop
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to make WP_Query ‘post__in’ accept an array?
- WP_QUERY Get posts by category and similar name (Like)
- Using get_posts vs. WP_Query
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Is it possible to wrap Geo Location search around WP_Query?
- Merging multiple wp_query objects
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- get_posts inside cron
- Using custom meta_query with relation not working as expected
- Only show first post to match certain criteria within WP_Query
- What is an efficient way to query based on post_meta?
- Pagination wont work with search results template [duplicate]
- Pagination Not working on Home Page with 2 Query
- WP_Query in a shortcode
- Get all posts without tags
- Sort by meta key on archive page
- Get post ID’s from one query and exclude from another
- What are the differences between “Latest Posts” and “Static Page”?
- Retrieve or Query Pages by ID
- WordPress Query is taking more then 20 second and stuck on creating index
- Modifying raw $_POST data early in the lifecycle
- Searching through different categories on different pages code is not working
- Get the Plugin Which Triggered a MySql Query in WordPress?
- Difficulty with rewrite rules
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- how to get the id for a post from within a post and return post meta for it
- Show selected images on top in Media Manager
- How to make this WP_Query run faster on a WordPress website?
- How do I sort posts with multiple pages
- Complex date range with WP_Query and BETWEEN
- Attachment changing page’s permalink – $post not resetting?
- showing all search result in one template
- List custom taxonomy terms sharing posts with a term from a second custom taxonomy
- Make (post) query a clickable link
- How to set pagination to work with ‘/page/’?
- How can I filter by slug depending on language selection
- How to duplicate 5 posts out of WP_Query results?
- Ajax WP_Query reutrns no results on author.php
- Large AND OR query timing out
- WP_query wp_posts_counts returns only count of admin and not users
- Categorising search results based on Custom Fields
- get_post_meta slowing down my page load (in a plugin)
- Custom taxonomy.php not working
- “tax_query” parameter is ignored when “p” parameter is set in WP_Query
- Conditional sorting with variable using WP Query
- How can i share WP_Query between multiple functions?
- Advanced WP_Query with meta_query, orderby?
- sort and display posts by custom field (wp-query and the loop))
- I need help using pre_get_comments to limit comments in the comments admin screen
- WP_Query Taxonomy categories filtering
- WP_query only displays one of my custom post type entries
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- How to create dynamic value in WP_Query meta_query
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- query post by author gender
- How to access $wp_query object from array of posts given by get_posts?
- Display all attached image of every post of custom post type and link to original post
- Links in the_content not linked
- how do I write this wp_query select statement?
- Post incorrectly excluded when using “category__in”?
- WordPress cron job running more than once
- How to search by slug and old slug in single API
- Reciving Error 404 blog/page/2/
- Categories In English version showing not canonical URL, instead shows query search result
- Multiple meta_query not returning rows
- Real cron killed my cron system. Only define( ‘ALTERNATE_WP_CRON’, true ); works
- What code to use in an array to call the current sub-category?
- Pagination for Category does not work
- Query against multiple locations within single custom post type post
- Order by meta date with a thousanth of a second defaults to post order
- How to debug none working search query?
- Order by Date Custom Field
- WP_Query showing all posts, except from category X, unless it’s also in Y
- How to make a search query if not found in post table then search in postmeta table?
- Show posts by category – category ID not working
- In which file to use $wpdb and its functions for database operations and queries in wordpress?
- Show All with Isotope
- Problem with infinite scroll on multisite with custom query
- active link for most recent post on vertical tabs
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- wp_query – show pages that have parent defined
- How do I display posts with specific value in a custom field into my loop?
- Orderby Meta Value and Query from Meta Query
- WP Query to order posts by multiple meta fields
- Order by multiple meta keys on wordpress
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- paginate_links() with Custom Taxonomy
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Get posts using multiple values from ACF checkbox as meta query wordpress
- Why ignore_sticky_posts argument is in sticky post query?
- WP Query returning all posts when Meta_query is null