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?
- CPU Overloading due to some hooks
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- One Child Functions.php for Multiple Child Themes
- Disabling pingback and trackback notifications
- register_post_type for Pages?
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How to get comments with mixed status using get_comments?
- Call to undefined add_action() in theme’s functions.php
- How can I rename the WordPress AJAX URL? [duplicate]
- How to add a rel attribute to images that contains their categories?
- Is it possible to be more page/post specific with admin_enqueue_script?
- What is the most efficient method for loading widgets in functions.php
- Enqueue script o style only if a template part is loaded
- Can I pass two roles to the function get_users?
- Add external js file to footer with id
- password protected post policy
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- How can I enable uploading excel files?
- Change the HTML of the comment form that is generating somewhere from the core WordPress
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- Twentyten Child Theme: header images display messed up in admin panel
- Removing wp_login_viewport_meta
- Get Current Post ID in functions php, meta query filter
- Call WordPress function outside of WordPress
- Move Custom Fields on General Settings Page to New Location
- Remove adjacent_posts_rel_link under 3.2?
- enqueue_script with filemtime javascript not working
- WP function won’t work on 404 template page
- How to obtain the recent posts without their content in an efficient way?
- Limit dimensions of “Full” size images
- Where to put random functions?
- Define PHP variable from a seperate API if statement
- Auto-Tweet if Type is ‘Status’ using OAuth
- Output a specific link in WordPress post if the single post’s category’s name contain certain word
- How to add custom li item to wordpress menu
- Passing user enetered value in widget: number of words, for example
- Adding a section in line at the end of the main navigation menu in php
- How to store a number (coming from cookie) into query vars for later usage in other filters?
- Suggest Users basing on User taxonomy
- update_post_meta is Updating with two page id
- Custom Image Size in Insert Media
- Custom function for search form
- Custom Menu in Admin doesn’t change menu in browser
- How can I show different content for different user-levels?
- WordPress function bloginfo not echoing output on parts of the pages
- How to change a meta value (of a published post) after X days.?
- sort metabox columns in listing Single
- wp_nav_menu displaying all pages
- WordPress cron job running more than once
- How to change text color depending on the number value (Using javascript)
- Why should I use get_template_directory() when include files?
- How to display an image before title text in menu items
- Error in “class-wp-hook.php”
- How to replace ACTION url from original wordpress login form?
- Redirect User Role When on Specific Page
- How to force one script to load before google tag manager script
- Ajax in plugin fails – but only on one blog – no idea why
- Real cron killed my cron system. Only define( ‘ALTERNATE_WP_CRON’, true ); works
- I can’t in any way include css in my theme using functions.php
- Problem with email function
- admin-ajax.php 403 forbidden only when calling from external file
- Display list of pages that contain a certain string within the slug
- I need to completely ‘wp_dequeue_script’; what’s the best way?
- $content is empty while using DOMDocument
- Change the second role depending on the first
- Problem with add_rewrite_tag
- getExcerpt: Make ellipsis appear only if character limit is reached
- Modify function Shortcode_atts
- How do I change the URL returned by next_posts_link()?
- WordPress SEO By Yoast Plugin is interfering with a custom function code – how to troubleshoot and fix it?
- Woocommerce – Checkout error message
- How to get postId from the argument $block when register_block_type()?
- My website is generating weired url parameters of paginated pages
- Logout redirect via page template without confirmation?
- How can I modify or filter this variable in an existing class? (Mai Theme)
- How to trigger an update_option