WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want an email to be sent to a specific list of email addresses if/when there have been no posts on the blog within the past 1 week. Any ideas on how I could do this?

share|improve this question
up vote 3 down vote accepted

You'll need to set up a cron job that checks once a day to see if the latest post is more than seven days old.

So, some where in a plugin file. Schedule a new event. Then hook into that event. Grab the post date, turn it into a unix time stamp, and compare that with the current time.

register_activation_hook( __FILE__, 'wpse29671_activation' );
function wpse29671_activation()
    wp_schedule_event( time(), 'daily', 'wpse29671_cron' );

add_action( 'wpse29671_cron', 'wpse29671_maybe_send_email' );
function wpse29671_maybe_send_email()
    // get the latest post
    $posts = get_posts( array( 'numberposts' => 1 ) );
    if( ! $posts ) return;

    // Latest posts date as a unix timestamp
    $latest = strtotime( $posts[0]->post_date );

    // how long has it been?
    $diff = ( time() - $latest ) / ( 60 * 60 * 24 );

    // if it has been more than 7 days, send the email
    if( $diff >= 7 )
        wp_mail( 'youremail@yoursite.com', 'Better Write a Post!', 'Hey, you should go write a blog post or something' );

As a plugin: https://gist.github.com/1246814

Alternatively, you could use DateTime objects to do the time comparison or just use this plugin (but it's way more fun to figure it out yourself, just sayin').

share|improve this answer
As a caveat, this will only work if you have consistent traffic to the site. This is a pseudo cron rather than a true scheduled server crontab job. It is solely based on page views to check if the wp-cron event should run. – Brian Fegter Sep 28 '11 at 2:24
A simpler date check: if(strtotime($posts[0]->post_date) < strtotime('-7 days')) ... – onetrickpony Sep 28 '11 at 2:47
Thanks a lot! looks like that works. – GavinR Sep 30 '11 at 4:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.