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
- Ways to create a paid wordpress plugin?
- OpenID for WordPress 3.x? [duplicate]
- Edit plugin without hooks in functions.php
- Template for different category on woocommerce product [closed]
- Trigger a custom wordpress plugin with a linux cron
- Allow a userclass to save a page as a draft – but not publish w/o admin approval
- Custom options page checkbox will not save, despite working with text
- Security checking in meta_box save is reluctant?
- What causes an Unexpected HTTP Error within install plugins?
- How do I write into a file (css)
- Cache WP remote_get HTTP Response using Transients
- What is an arbitrary URL?
- Allow users of my plugin to define their own shortcode rather than use mine?
- Timed Exam test for candidates [closed]
- There has been a critical error on your website. Please check your site admin email inbox for instructions.Learn more about debugging in WordPress [closed]
- How to call WordPress function other files
- Plugin alternative to Normalize.CSS? [closed]
- WordPress Plugin manipulate have_posts()
- Where are theme codes located for WordPress?
- call_user_func_array() expects parameter 1 to be a valid callback
- Inserting custom PHP script on homepage
- a weird attribute on every html tag
- Add bcc to contact from on wordpress
- Which wordpress theme is compatible Optima Express theme (real estate inventory) plugin?
- Fullscreen gallery plugin [closed]
- List category posts displaying limited posts
- WordPress Site is Broken, Cannot see wp-admin page [closed]
- Fetch CSS of posts
- Fancybox plugin: triggering on href attribute
- Gravatar alternative for WordPress
- Single Domain/Multiple Domain installation restrictions allowed for plugins?
- Plugin to display weekly schedule that can be edited via admin panel
- Replace the_content with ACF Flexible Content via function
- WordPress to be used more like an app?
- WP_get_image_editor resizing images in a foreach loop
- WP core and plugin updates fail AWS
- Custom product page’s style for printing
- WordPress Admin sub-level menu issue
- Why does WordPress use cookies for /wp-admin and /wp-content/plugins for non-admin users [duplicate]
- How to add subdomain to htaccess
- Add class as plugin for other plugins
- Hidden Some Setting on Post or Page [duplicate]
- How do I secure a subdomain using UCC SSL?
- Template from scratch: Sidebars not showing widget
- Home not showing in yoast breadcrumb
- Contact Form 7: custom validation [closed]
- Redirect url in plugin to somewhere else?
- Trouble Removing Plugin [closed]
- Output plugin post like system count [closed]
- plugin translations not reflected in admin dashboard
- Elementor with system colors instead of kit colors [closed]
- Shortcode inside a redirect [closed]
- Private plugin updating – GitHub zip file changes the plugin directory (with release or branch name)