-2

I'd like to send an email (only one) to a specific user every 12 months after a given date. Would you please provide me with the PHP code that would allow me to specify the starting date and send the email?

| improve this question | | | | |
2

Set update_user_meta() for a WP_User if get_user_meta() ends up empty.

Update a key with a future date for the next year:

$startDate=date('Y-m-d');
$futureDate=date('Y-m-d', strtotime('+1 year', strtotime($startDate)) );

Schedule an event in one year with wp_schedule_event() or use 'daily' to check all users for a relative year date.

// WP_User_Query arguments
$args = array (
    'meta_query'     => array(
        array(
            'key'       => 'future_email_date',
            'value'     => date('Y-m-d'),
            'compare'   => '<=',
            'type'      => 'DATETIME',
        ),
    ),
);

// The User Query
$user_query = new WP_User_Query( $args );

When you find a match, use wp_mail() to send your email.

| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.