Another wordpress and campaign monitor tip

Here is another tip for sending emails in campaign monitor. This would basically run manually/from a cron job. For more information on where the below came from, there is a detailed description on my blog.

<?php 
define('WP_USE_THEMES', false);
require('/the/path/to/your/wp-blog-header.php'); //found in the root of your WordPress install.
switch_to_blog($blogID); //if your in a multisite
$latestPosts ='';
$args = array(
    'posts_per_page' => -1,
     'post_status' => 'publish'
);
function filter_where( $where = '' ) {
    // posts in the last 30 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; //change 30 to the number of days you want
    return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $args );
remove_filter( 'posts_where', 'filter_where' );
$count=0;//counter to see if there are posts
while ($query->have_posts()) {
   $the_query->the_post();
   if (get_the_title()<>''){
        $title=get_the_title(); 
        $summary=the_excerpt();
        $latestPosts .="<p>$title<br>$summary</p>"; //be sire to include CM message
        $count++;
   }
}
if ($count<>0){
              //Campaign monitor code to send emails
}
?>
roshodgekiss roshodgekiss, 3 years ago

Hi jtesolin, this is very useful - thanks for posting! Keep the good tips coming in. :)


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor

Join 150,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098