Home Forums Add-ons Options Page Use shortcode in textarea on options page in loop


Use shortcode in textarea on options page in loop

  • I have an option page where you can save an email body text to send out to customers. To make it personal I use shortcodes within the body text like this:

    Dear [yl_first_name],

    How are you today?

    Kind regards,
    Team X


    The email sends out with WordPress cronjob and all works fine except for 1 thing:

    Because ‘officially’ the FIRST NAME is NOT called in the below WordPress loop >> Its the shortcode that is called (via the option page) in the loop…

    I always get the same name value (latest post in line).

    Here’s my EMAIL SEND code:

    // Follow-up e-mail met reviewverzoek
    function yl_follow_up_email_review_function() {

    $review_days_after = get_field(‘booking_settings_review_delay’, ‘booking_settings’);
    $review_url = get_field(‘booking_settings_review_url’, ‘booking_settings’);

    if ($review_days_after && $review_url) {

    $bookings = array(
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘booking’,
    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    ‘key’ => ‘booking_status’,
    ‘value’ => array(‘confirmed’, ‘changed’),
    ‘compare’ => ‘IN’,
    ‘key’ => ‘booking_send_mail’,
    ‘value’ => ‘ja’,
    ‘compare’ => ‘=’,

    // De Query
    $query = new WP_Query($bookings);

    // De Loop
    if ($query->have_posts()) {
    while ($query->have_posts()) {

    // Controleer of de poststatus ‘publish’ is
    if (get_post_status() == ‘publish’) {

    // Verkrijg aangepaste velden van de huidige boeking
    $to = get_field(‘booking_email’);

    // Zorg ervoor dat deze velden bestaan in je booking_settings
    $booking_settings_id = ‘booking_settings’; // De ID van de booking settings post

    $sender_name = get_field(‘booking_email_from_name’, $booking_settings_id);
    $sender_email = get_field(‘booking_email_from_email_address’, $booking_settings_id);
    $subject = get_field(‘booking_email_subject_review’, $booking_settings_id);
    $message = get_field(‘booking_email_message_review’, $booking_settings_id); // the above body text with the shortcode inside

    $headers = array(
    ‘From: ‘ . $sender_name . ‘ <‘ . $sender_email . ‘>’,
    ‘Content-Type: text/html; charset=UTF-8’

    // Verzend de e-mail en log eventuele fouten
    if (wp_mail($to, $subject, $message, $headers)) {
    error_log(“Email successfully sent to $to for booking ID: ” . get_the_ID());
    } else {
    error_log(“Failed to send email to $to for booking ID: ” . get_the_ID());

    // Update met nieuwe waarde
    update_field(‘booking_status’, ‘completed’);

    // Pauzeer 10 seconden voordat de volgende e-mail wordt verzonden

    // Reset de postdata
    add_action(‘yl_follow_up_email_review’, ‘yl_follow_up_email_review_function’);

    The Shortcode code:

    // Get ACF ‘First name’ values via shortcode
    function yl_booking_first_name_shortcode() {
    global $post; // Haal de globale $post variabele op
    return get_field(‘booking_first_name’, $post->ID);


    So how can I change the code so the correct name in each email is showing?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.