It’s because your code is explicitly written to ignore whether or not the event is in the past or the future.
See here:
$diff = strtotime($my_meta) - strtotime($datetime2);
If the event date is in the future, $diff will be a positive number, but if it’s in the past, it will be a negative number. Then the very next line is:
$gap = abs(round($diff / 86400));
The whole point of the abs() function is to make sure a number is a positive number. Which means that the result will be exactly the same whether the event is in the past or in the future.
If you only want to send a notification for upcoming events then you need to know if the number is negative. So just remove abs() and make sure that you’re only checking for 3 and not -3:
$diff = strtotime($my_meta) - strtotime($datetime2);
$gap = round($diff / 86400);
if($gap === 3){
// etc.
}
Related Posts:
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- Schedule WordPress Auto-Updates to only run during business hours
- How to make sure a wp-cron job runs
- How do I email a new page password to somebody every month?
- What happens when wp_cron is deactivated in WordPress?
- Long running action from plugin
- Posts wont expire
- Custom interval is not working
- Cron Job not working in plugin
- How to use wp-ajax in wp-cron
- wp_schedule_single_event function not working
- How ( and mostly at what time ) can i prevent the alternate cron from running?
- action-scheduler vs wp-background-processing
- Remove obsolete plugins artifacts from database tables
- Why is wp-cron only executing on page visit?
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- Cron job not firing
- How make a php script run only with wp-cron
- Does using WP-cron make the site slower for the user?
- wp_schedule_single_event not working: cron job is triggered but nothing gets executed
- How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
- How to make a implement queue for scheduling tasks in WordPress?
- Automatic plugin updates not working
- Cron Job not working in plugin
- Setup wp_schedule_event within a custom plugin
- How to set intervals in cron jobs?
- get_edit_post_link() not working on wp-cron
- get_users(); Is an Undefined Function When Used in Cron Job
- Switch from wp-cron to a server cron job
- What causes wp_schedule_single_event to fire off?
- WordPress cron job running more than once
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Save log for imports in WordPress database – options-table, custom post type or other place?
- Cron: Update four post at Hour
- Activate Plugin Automatically After Set Time
- get_posts query results out of order but shows correct in php snippets plugin
- Scheduled cron event removed from list automatically after sometime
- WP_CRON issue with UTC and local time
- Better way to run heavy scripts using WordPress database
- wp_schedule_event function reference
- WordPress Cron function is not working
- WordPress crob job performance
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- Adding custom cron_schedule prior to wp_schedule_event
- Using a Cron Job to dynamically populate a field ONCE, and then making the field blank the next time someone visits page
- Plugin Hooks Not Shown in WP Cron Jobs
- Running a function using Crown WordPress on one day a week, for example, Mondays of every week
- WordPress “wp cron event run” as Siteground cron job
- Cron Job not working
- Which approach for managing automatic updates would be more robust?
- Render CMB2 select option to post page [closed]
- How can I utilize the same “show more” functionality that I see in superuser on my own WordPress site?
- WDTException: [0]: One or more columns doesn’t have a header
- How to Add Extra Text In WordPress Title Before Post Publish
- How can I make a quotation engine like this website in WooCommerce?
- Function not being called on form submit, only blank admin-post.php page
- how to get the url of a custom uploaded file
- Gutenberg Block to Select Category Term
- Update post meta Rest Api
- cURL External API request displays content above other content on page
- A way to upload old html pages with all its assets via WordPress admin and to add a fixed menu on top of those (a la Wayback Machine)
- Problems with file_exists() with metabox plugin in WordPress
- How to rewrite URL using .htaccess in WordPress Plugin
- Footer option is missing in Customiser
- WordPress Convert queries to slashes using function.php
- 404 Error on a WordPress Website, Error disappears for a while and again appears
- ShipStation WooCommerce Integration error
- Failed to update a post when I add a taxonomy to it
- Add Text in Single Product Page On a Specific Category
- How to give specific class name to category in wordpress with code snippets
- Problem moving to category posts page
- admin_enqueue_scripts using hook_suffix vs GET page
- FacetWP custom display based on post type [closed]
- Is Nonce Verification (CSRF) required for WordPress Custom Bulk User Actions?
- List Hidden Plugins
- Not Able to Edit Homepage After Updating Elementor
- How to fetch data from the two plugin’s data on the frontend?
- Wp Plugins Update
- i need to resive data external api and show user
- Getting table to format properly in RSS feed emails
- Getting table to format properly in RSS feed emails
- How to fix a Wordfence scan that doesn’t finish?
- WordPress.Security.NonceVerification.Recommended
- My Revolution Slider suddenly appears two times after updating
- BBPress Customization with Custom Plugin
- WooCommerce Bookings – Last day of booking available for the next customer
- How to make cookies notice load after everything else?
- ASSOCIATE YITH BRAND WITH PRODUCT
- Unable to register rewrite rule using add_rewrite_rule
- PHP Deprecated function Optional parameter $function
- Missing Contact Form/Form Default Plugin in WordPress
- Plugin for better Backend Search? [closed]
- How do I apply different block supports to different parts of my custom block?
- Remove 3rd party plugin notices from within own plugin
- How to add entity in WordPress that have metadata such as name, age
- Edit Image button disappears when I make WordPress use Imagick instead of GD
- Order Posts Using Taxonomy Term Facetwp [closed]
- Is there potential plugin incompatibility if theme has no header.php and footer.php?
- Is SSL connection of plugins default?
- Custom Gutenberg blocks not showing in WP editor