Laurens
Laurens

Reputation: 2420

Reminder to author of wordpress post after exactly 1 month

For a wordpress site I have to implement a reminder that will be send 30 days after the creation of a post in wordpress.

For example:

Author creates a post, 30 days after the creation of this post the author will get a mail on the email-address which he/she filled in at the admin profile dashboard.

The mail needs to contain a url to the original post.

Are there any available plugins that could help me or should I write a custom function ?

Thanks in advance.

Upvotes: 0

Views: 1731

Answers (3)

Laurens
Laurens

Reputation: 2420

For a temporary solution I did the following:

I downloaded the plugin 'crony cronjob manager'

This plugin let's you run custom php at a specific time-interval.

My custom php looks like this:

<?php

  $query = "SELECT * FROM wp_posts
         WHERE post_type = 'catalogus'
         AND post_date BETWEEN '" . date('Y-m-d', strtotime('-30 days')) . "'
         AND '" . date('Y-m-d', strtotime('-29 days')) . "'";

  $allposts = $wpdb->get_results($query);

  if($allposts){
    foreach ($allposts as $post) {
      // get post name for url 
      echo "http://xxxxxx.xxx/product/".$post->post_name;
      // get author email to send mail to.


      $to = get_the_author_meta('email',$post->post_author);
      $subject = "XXXXXXXXXXX";
      $headers = "From: XXXXX <[email protected]>";
      $message = "Dummy message";
      wp_mail( $to, $subject, $message, $headers, $attachments ); 
    }
  }
  else{
    echo "No posts";
  }
?>

This is still no perfect solution, because like Chris mentioned above, this cronjob will only run if a visitor makes a request, my next step is to write a real cron job or scheduled task that will execute the code above.

Upvotes: 0

Cyborg
Cyborg

Reputation: 11

You need Blog Update Reminder.

I have modified this plugin to suit my needs. I´m sure you will like it ;-)

http://wordpress.org/extend/plugins/blog-update-reminder/

Upvotes: 1

CLo
CLo

Reputation: 3730

The problem you're going to run into is that PHP runs when a user makes a request. So, if no one visits the site on the right day or at the right time, the code you want may not run. And even if they do, do you want to slow down a random users request for this functionality.

It's best if you look into a Scheduled Task (windows) or Cron Job (linux). These utilities can be used to run PHP scripts at specific times or with specific intervals (every hour, every day at midnight, etc.). Then you create a PHP script that does the work of finding the specific posts and sending emails.

If your hosting provider doesn't allow access to a scheduling utility. You could setup your own computer, or another computer with a scheduled task to call a specific PHP file that does this work.

Upvotes: 3

Related Questions