Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

daily job to run send email based on user data

You can go about it this way, explanation in pseudo code and in the comments.

Create a function like the following in your functions.php file:

/**
 * This function collects the tasks that are due in a week and sends a reminder
 **/
function check_user_tasks_week_before() {
 // query which Completion Dates are in a week
 // loop through the results (if any)
 // and send every user in the result (or every task that is almost due) the email:
  // Send a mail:
  wp_mail( '[email protected]', 
   'Your task should be completed in a week', 
   'Hey, the deadline for your task blablabla is due in a week, get going or else!');
}

(For info about how to attach an image see this page at the WordPress codex.)

To schedule the task with wp_cron, so it runs every day, create a function like this in the file functions.php:

// If the task does not exist yet, it is created here:
if ( ! wp_next_scheduled( 'my_task_hook' ) ) {
  // you can specify what time() it should run (it is a unix timestamp)
  // in your case 'daily' would be a good choice:
  wp_schedule_event( time(), 'daily', 'my_task_hook' );
}

add_action( 'my_task_hook', 'check_user_tasks_week_before' );

Related Posts:

  1. Is there a quick way to view the wp-cron schedule
  2. Should I disable WP_CRON and instead trigger wp-cron.php from server every few mins?
  3. Do WordPress cron jobs slow down page loading?
  4. PHP Warning on fresh install (Connection timed out)
  5. Is there a known vulnerability for wp-cron.php?
  6. WordPress cron isn’t scheduled on amazon web services
  7. Using wp_schedule_single_event with arguments to send email
  8. wp_schedule_event is executing but the function related to the hook is not running
  9. How to use wp_schedule_event in a class?
  10. wp_schedule_event won’t accept args
  11. add_action to wp cron?
  12. Triggering cron by calling wp-cron.php on the command line rather than with wget?
  13. Run WP Cron Weekly (but on a certain day)
  14. wp-cron.php is triggered, but scheduled post is not published
  15. Get frequency of scheduled event
  16. wp_schedule_event() on specific time, daily
  17. wp_next_scheduled returning a past timestamp
  18. crontab wp-cron.php on multisite path-based network: one for each path? Or just one for the root?
  19. Missed scheduled WordPress
  20. Running wp-cron from CLI
  21. Do wp-cron scheduled tasks run asynchronously?
  22. Some rogue WordPress plugin killing my server – how do I isolate and kill it?
  23. Why?: hundreds of empty files named wp-cron.php?doing_wp_cron.
  24. Can’t access wp_filesystem in cron function
  25. WP CRON runs only the first time
  26. Run a cron job (or similar) in the background of WP after post update/create
  27. what is firing cron
  28. wp-cron still running even though DISABLE_WP_CRON is true
  29. Managing scheduled tasks
  30. custom cron interval is not working
  31. How to set up WP Cron in this scenario
  32. Where in the page load code is wp-cron triggered?
  33. WP-Cron tasks scheduled but not running
  34. Can’t find wp-cron.php but I can see it in the public folder [closed]
  35. Manually trigger a wp_schedule_event item?
  36. Check if event was scheduled – schedule event only once
  37. wp_get_schedule and wp_next_scheduled don’t find my scheduled wp-cron job
  38. Getting Error “invalid secret string” by running wp-cron.php manually
  39. WordPress wp-cron not working
  40. Too many wp-cron requests even when disabled
  41. Why cron doesn’t work to me?
  42. Why would wp_schedule_single_event get delayed start?
  43. Wp cron event is set but the function isn’t getting fired
  44. Is doing_wp_cron a necessary query string when scheduling cron.php as a cron job?
  45. Run a php file daily at specific time
  46. Create function in functions.php with hook name to execute URL
  47. cron.php being constantly deleted [closed]
  48. Scheduling posts on wordpress adds wrong seconds as post_date
  49. WordPress Cron is scheduled but not running
  50. How to make WordPress emails async
  51. How to execute existing WP Cron programmatically
  52. Cleaning “cron” from options table, will affect anything?
  53. Execute code at the end of each quarter of year
  54. debugging wp_cron jobs with XDebug in Eclipse
  55. wp_schedule_event run in background or not?
  56. Trigger background job using AJAX
  57. Detect if Cron is Running
  58. Run function with linux cron job in WordPress
  59. Schedule cron don’t work
  60. How to code schedule / cron job
  61. wp_schedule_event daily at specific time
  62. Pings disabled but WordPress is still searching for “to_ping”
  63. Cron schedule not updating after run
  64. How to schedule and publish a post after it’s ready?
  65. Can you register two cron events in a single function?
  66. wp_schedule_single_event does not call my action
  67. Hourly scheduled wp_cron job keeps getting rescheduled
  68. When to use wp_schedule_single_event for async / non-blocking processes?
  69. wp-cron.php – timeout
  70. Failed to open stream: HTTP request failed! in \wamp\www\wordpress\wp-includes\class-http.php on line 929
  71. wp-cron: freeze at “now”
  72. How could an event previously scheduled with wp_schedule_event later become unscheduled?
  73. daily wp_schedule_event hook works after reload any page
  74. update post every day
  75. WP Cron jobs loops infinitely
  76. Scheduling a cron job from a function that is ran outside functions.php?
  77. Issues When Recursively Calling wp_schedule_single_event()
  78. Sync user meta fields using Wp cron job
  79. wp-cron behaviour when there are multiple queued tasks
  80. Why is `wp_unschedule_event` not working
  81. System Cron job not firing
  82. WordPress Cron Job Not working
  83. WordPress action hooks related to scheduled posts not Fired
  84. Cron Job Keep Running in spite of being disabled
  85. WordPress automatic publish: is there a timeout when WordPress won’t publish anymore?
  86. How to create a WP Cron hooks based on schedules from Advanced cron manager plugin?
  87. Cron job not working – Can’t see in the queue attached
  88. How to fix missing function in wp-cron?
  89. Sending email to all users
  90. “Missed schedule” posting bug
  91. Run function after a post has finished saving – callback function perhaps?
  92. How to force ‘cron_schedules’ every minute instead 1 hour?
  93. WordPress, how to run a function every 12 december?
  94. Cancel/Stop a currently ongoing scheduled cron event?
  95. When running WordPress Cron manually, it shows WP-Cron spawning is disabled. What is WP-Cron spawning?
  96. Wp Cron and WordPress Updates
  97. Code does not work in class implementation but works fine in functions.php file
  98. Use cron to create a non blocking task
  99. How to create and run cronjob in WP without using the plugin?
  100. Cron job to run just once per day using external cron service
Categories wp-cron Tags html-email, wp-cron
What do “and” means infront of a variable? [closed]
Pagination not working in home page

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress