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.

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()) {
   if (get_the_title()<>''){
        $latestPosts .="<p>$title<br>$summary</p>"; //be sire to include CM message
if ($count<>0){
              //Campaign monitor code to send emails
roshodgekiss roshodgekiss, 4 years ago

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

Get in touch with us on Twitter:
We're also on Facebook:

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