• I customized a spider calendar plugin which shows today’s birthdays and current months list of wedding anniversaries in the home page of the site. i wrote a code in that plguin’s displaying page using wp_mail and mail will send. but this happens only when the site is visited. my code:

    if($dat==date('Y-m-d'))/*$dat is the date of event from DB*/
     {
      if($eid!=''){ /*if recipient email id is not null*/
     if($se!=1)  /*if email is sending first time then($se=db column 'send'value) $se=0    otherwise it is 1*/
      {
        $to=$eid;
        $sub="Birthday Wishes";
        $msg='Happy Birthday '.$ev_title[$j];
        $headers= 'From:Mysite <[email protected]>' . "\r\n".'Content-type: text/html';
        $attachments=array(WP_CONTENT_DIR . '/plugins/spider-event-calendar/images/happybday.gif');
        $rx=wp_mail($to,$sub,$msg,$headers,$attachments);
        $wpdb->update($wpdb->prefix.  "spidercalendar_event",array('send'=>1),array('id'=>$ev_id[$j]));/**/
        //echo "email send";
        }
      else{
      //echo "email already sent";
          }
        }
      }

    i heard aboywp_cron. as i’m a newbie can anyone please tell me how should i write a cron from the above function to perform.and how to start the cron.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Casey Driscoll

    (@caseypatrickdriscoll)

    Hi Nikki,

    I was curious to learn more about WP-Cron, so I thought I would tackle this question.

    Here is a good primer on WP-Cron >>
    http://code.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress–wp-23119

    At first glance, I’m not sure WP-Cron will help you, because it also only runs when the site is loaded, even if they are scheduled into the future. If you have a site that doesn’t get much activity, events will be missed because the page is not being accessed.

    My get says what you want is a real *nix cronjob. Are you on a linux server? Who is your host?

    I’ll see if I can figure out more info.

    Thread Starter nikki007

    (@nikki007)

    yeah i’m using linux server.

    Moderator bcworkz

    (@bcworkz)

    You can setup cron jobs that run at a specified time regardless of site traffic. How this is done varies by host, your control panel should have a “Cron Manager” or a pick for “Cron jobs” or something like that. Your host should be able to help you if you can’t find it.

    You will want to schedule wp-cron.php to be run in the cron manager, I suspect daily. You will also need to modify your code into a function, then add it as an action callback. Finally, you schedule the action as an event. All this code can be in a plugin or on your theme’s (preferably child theme) functions.php.

    You still are using the WP version of Cron which requires a site visit to trigger your action. You are then using the Linux Cron to ensure a site “visit” occurs on schedule.

    It’s possible to bypass the WP Cron portion, but you need to have code that is directly executable, which is a bit tricky to do correctly with the WP environment.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_cron usage’ is closed to new replies.