In your functions.php you can use this. You will have to activate your theme again for it to take effect. You only want to schedule a cron job on activation, not on activation NOT on every page load, which is what the functions.php does, it loads on every page load.
This would be betterused in a plugin.
register_activation_hook(__FILE__, 'cron_job_activation_hook');
function cron_job_activation_hook() {
wp_schedule_event( time(), 'daily', 'ron_posts_emails');
}
add_action('ron_posts_emails', 'ron_send_daily_posts_email');
function ron_send_daily_posts_email() {
$args = array(
'numberposts' => 10,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'reservations',
'post_status' => 'draft, publish, future, pending, private',
'suppress_filters' => true );
$recent_posts = wp_get_recent_posts( $args, $output = ARRAY_A );
//mail stuff hurr
}
Related Posts:
- How can I send an email using PHP?
- Running WP Cron on multisite the right way
- WordPress refuses to send mail, “…your host may have disabled the mail() function”
- How do I override the Message-ID header of wp_mail function?
- What would be a PHP command to erase all posts from category X from the last month?
- Initialize WordPress environment to use in a real cron script
- How to disable wordpress confirmation email for new users
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- Run W3 Total Cache Flush Function with Crontab [closed]
- Best way to create a user programatically
- Should I use wp_mail or PHP’s mail? [duplicate]
- Mail not sent when I set HTML headers
- Send PDF link in email based on radio button selection
- Woocommerce HTML email option unavailable
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- Trigger Woocommerce New User Email
- Processing a subscription form with POST method?
- Different Webhost and using Google Mail server: Is there a better way than SMTP?
- How to get woocommerce cart content without an action?
- WP_cron won’t trigger my action
- Attaching a pdf to Contact Form 7 e-mail via functions.php [closed]
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- Set a condition based on WooCommerce checkout city field while placing order
- WooCommerce – Email admin with new user details
- How do you ensure that a user is recognised and available for use only when it is verified through a row in the database called ‘accountVerified’?
- export a csv file from the database with a cronjob
- PHP 8, AJAX mail form to function.php doesn’t work
- Capture User Email Address When Filling Out Form
- How to bypass maintenance mode with external cron?
- Send multiple attachments with wp_mail in PHP
- How wp-cron can run in background if PHP is single threaded?
- WP Cron job timeout issues
- running wp-cron.php using php not wget
- How to retrieve the sender email with wp_mail()?
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Can I get an email notification when media is uploaded to the media library?
- Woocommerce Email attachments not working – file not being attached
- Large WordPress CRON job
- How to Schedule Cronjobs for start of every month and year
- Get user custom field value on function.php
- Pass return-path additional parameter in wp_mail
- difference between sanitize_email ,FILTER_VALIDATE_EMAIL and input email type in html5
- WordPress cron is running with previously set time intervals and not the updated one
- Use of antispambot with $curauth->email
- How do I attach an invoice PDF to an email in the Dukapress plugin for WordPress?
- Contact form – problem with displaying message about sent mail
- Unzip file in functions.php, and add it to cron
- Can/should we delete wordpress cron jobs with no action?
- How to setup the Email piping in WordPress plugin?
- Is it secure to use SMTP password in .php file in WordPress website?
- Send an e-mail on address with the link with disliked post
- Wp_Schedule_Event every few minutes doesn’t work
- Setting up a cron job to auto update a custom field
- I want to fusion the product columns in email table order
- Woocommerce checkout page – custom field checkbox value into email
- CRON job to update wp_usermeta value each day or week based on server time
- Cron not sending wp-mail()
- Php cron job (wp-cron) not working
- Changing default WPMU emails to be send thorugh Campaign Monitor Transactional emails
- Send email to users when they get new followers
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- How can disable wordpress emails notifications?
- Woocommerce custom field on emails outputs ‘Array’
- Using Custom Javascript and pHp to send email to myself when a user clicks on an input button but only works on Chrome, IE, and Micorosft Edge
- Wp_mail doesnt work
- Trying send mail from Theme page
- get_post_meta is always empty when I use wp_mail
- How to check “From Email” via WordPress before an email is sent
- How does one programmatically manage posts from a external php script?
- Adding multiple emails to a
- wordpress.org disallowing my plugin becuase of loading core files in cron cpanel file
- How can I prevent wordpress from sending emails
- Dynamic Email Handler with ‘header (“Location: …’
- Customize the summary table of an order in the email
- Why does WordPress not send the user the email to add a password?
- Why is my custom email notification after purchase not sending?
- How do I enable HTML5 prefetching on this page?
- user_id error: Only variables should be passed by reference
- Mute Debug Messages from Plugins
- Reprinting tags with all attributes
- database sent to a JSON file
- How to include seperate PHP file to class in callback function
- Display css ONLY on most recent post of specific category?
- Calling PHP Titles inside Javascript Markup
- How to replace the default domain on wp get shortlink
- add the value of a variable returned in a while loop [closed]
- How do I edit the terms output args or array data?
- Gutenberg Blocks and get_option() for styling
- Non-blocking file_put_contents in function.php
- WP_QUERY post_in problem
- custom taxonomies not working
- Should I set a page as “No-index” if I include it’s content within the front-Page.php via this method?
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Perfmon performance counters on WAMP
- media-uploader insert into post is not inserting
- Page 2+ of taxonomy archives does not recognise sort-order from dropdown
- Is this correct get_template_part() in WordPress?
- Editing a WordPress plugin to add my own functionality
- Get unique post in parent category
- Edit Error Page style