Categories
Web Development

Releasing Content over Time / Drip Campaign with WordPress

Using the Date Registered field in WordPress you can create a page that releases content over time. In this example we are creating a Drip Campaign for content released in a specific category.

In this example I have set up a category called “Campaigns” and within it I have added subcategories called Week 1, Week 2, Week 3 etc. The goal is that every week a new section will be released, so if the user registered, week 1 is available instantly, then 1 week later week 2 becomes available and so on.

$dateRegistered = strtotime($current_user->user_registered);
$now = date('Y-m-d H:i:s', strtotime('now'));
$categoryId = 99;

$catArgs = array('taxonomy' => 'category', 'parent' => $categoryId, 'hide_empty' => false);
$categories = get_terms($catArgs);
$dripIncrement = 7;
$startNumber = 0;
$counter = 0;
$number = 0;
$weeks = array();

foreach ($categories as $category) {

    if ($counter != 0) {
        $number = $number + $dripIncrement;
    }
    $weeks[$category->term_id] = date('Y-m-d H:i:s', strtotime('+' . $number . ' day', $dateRegistered));
    $counter++;
}

$listStyle = '';
foreach ($weeks as $weekId => $releaseDate) {

    // If is enabled
    if ($now >= $releaseDate) {
        $listStyle .= '
            li.cat-item.cat-item-'. $weekId .',
            li.cat-item.cat-item-'. $weekId .' a
             {
                color: green;
            }
        ';
    } else {
        $listStyle .= '
            li.cat-item.cat-item-'. $weekId .',
            li.cat-item.cat-item-'. $weekId .' a {
                color: red;
                pointer-events: none;
                cursor: default;
            }
        ';
    }
}

The above create a loop for for the subcategories in my Category Id, and using an increment of 7 days it will add one type of css if the registered date is within range and another if it is not. We then take the following and add it before the tag.

<style type="text/css">
    <?= $listStyle ?>
</style>

Finally, we use the WordPress list categories function to print a list of all the subcategories, the $args variable allows to tweak things like printing a title, printing if the subcategory has no content, etc.

<?php
    // List subcategories of Campaign
    $args = array(
        'child_of'            => $categoryId, // 10 Week Plan ID
        'title_li'            => false, // Hide Title
        'hide_empty'          => false
    );
?>

<?php wp_list_categories($args) ?>

Leave a Reply