This happens because this code:
if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) {
wp_schedule_event( time(), 'every_one_hoursinwp', 'myprefix_cron_hook',array(42));
}
Is the same as this code:
if ( ! wp_next_scheduled( 'myprefix_cron_hook', array() ) ) {
wp_schedule_event( time(), 'every_one_hoursinwp', 'myprefix_cron_hook',array(42));
}
And while you have lots of cron jobs with array(42), there is no next scheduled cron job with no arguments, so the if statement is true.
To fix this, use the second parameter of wp_next_scheduled:
https://developer.wordpress.org/reference/functions/wp_next_scheduled/
Think of it this way, if you had multiple cron jobs with different arguments, how would you check which ones have been scheduled if you couldn’t pass the arguments?
Related Posts:
- Automated mark posts as featured every day
- WordPress function, Run using Crontab
- Display a random tag but using cron to control frequency of change
- Bulk updating a group of WordPress Pages every 10 minutes
- How to run a function every 5 minutes?
- Do WordPress’ cron’s clean up expired transients?
- WP_Cron doesn’t do the job: Multisite stats
- Update Content based on expiration time or queued processing
- Create cron job for update translations automatically
- Can/should we delete wordpress cron jobs with no action?
- Run function with schedule is not working correctly
- Writing a function for WP Cron to run a SQL command daily
- Deleting guests profile users after 1.5 hours
- Scheduled post delete – can’t pass the cron arguments
- WP_CRON issue with UTC and local time
- How to add a cron job in my functions.php
- Remove Featured Images from Posts Older Than a Certain Date
- Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
- Working function() doesn’t execute when triggered by WP CRON
- Update post meta with wp cron
- HELP: Code To Check Status And Write Debug Entry
- Function attached to cron job not running but will run if called manually
- Submit CF7 form programmatically with WP-Cron?
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?
- Is it ok to use a function to output the text domain name in a wordpress theme
- How to use the do_action () with parameter
- Issue with wp_get_attachment_image() and SVG file type
- TinyMCE custom styles remove class when switching styles
- deregister scripts on certain page
- contactform7 remove tags with “wpcf7_autop false” from functions.php
- How to count number of functions attached to an action hook?
- Extending the site search to include a single custom field
- Notify users whenever a new post is published based on their preference
- Recurring scheduled task help
- ajax live search for post title
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- syntax for remove_filter in parent theme with class
- Scheduling posts to update once per day with wp_cron
- How to get an array of menu items from the toolbar?
- Remove Header and Footer in iframe
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Using get_terms for custom taxonomy in functions.php
- How to Acheive the custom woocommerce category template
- Can I remove the Rich Text box editor for a specific post?
- Formatting post content to exclude gallery
- Why do I get undefined function export_wp()?
- How to remove the embed_footer?
- Hide some items from Screen options in dashboard for products
- Redirect if not logged in?
- How to set global variables in template page?
- Check if event was scheduled – schedule event only once
- Editing or filtering the output of the Genesis navigation
- Programmatically set page template based on page ID
- Setting featured image with function, 1 part not working
- Function to show only first instance of shortcode
- Best way to programatically add “rel” attributes to page and post images
- Comments to only be seen by their author
- Using the child theme functions.php to change the customizer.php on parent theme
- Can’t Update function.php after writing short code
- How to get last updated row or ID in wordpress
- How to notify the admin about something that happened during a cron job
- Create function in functions.php with hook name to execute URL
- cron.php being constantly deleted [closed]
- Remove function or filter
- options.php problem – data not saved
- Filtering posts by category name based on page’s slug
- adding custom classes for tables
- Load parent theme files before child theme functions.php
- 2 Loops, Only Displaying 1 Loop in Both Loops
- edit role display name and label name without plugins
- is_plugin_active() not properly returning true
- Display gallery on top before content
- List of Body Classes Generated by body_class()
- CSS for menu item added via functions.php
- Two functions.php files in one theme
- wp_dropdown_categories and custom attribute
- Converting html to wordpress images not showing
- Run function with linux cron job in WordPress
- Schedule cron don’t work
- Default Gallery Edit/Template Editable?
- WP CRON on shared hosting that does not allow loopback connections?
- Redirect specific page in WordPress for first time visit
- Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘greenday_head’ not found or invalid function name
- How can I add text to all posts/pages/categories/homepage etc
- Make parent page only link to first subpage
- When to use wp_schedule_single_event for async / non-blocking processes?
- Pulling Twitter RSS feed not working as expected (fatal error)
- Related post using post title
- How to validate this deprecated function
- Move Post to different category if post_meta field is 0 or is 2 days old?
- Display alert on successful user Sign Up
- Getting different functions data while using while loop in wordpress
- How can I modify all existing tags while keeping the urls themselves?
- Scripts not appending to element in AJAX call – why?
- Trigger a custom function when option are saved in admin area
- Find a Javascript ID when trying to deregister?
- Functions.php – Cannot Modify Header Information SOLVED [closed]
- Functions For Calling Specific Elements
- Set spesific size of featured images
- How would I add “edit profile” and “blog post” functions to front-end?