• Resolved Kamio

    (@dotnetdiva)


    I am trying to use the Custom Markup Variable feature to display a different name based on what a button group value is. My sample code is below, and I’m outputting the return value as {baseDescription}. My ACF Button Group choices are:
    Base
    Expansion

    <?php
    $isExpansion = ”;
    if($base_game$ == ‘Base’)
    $isExpansion = ”
    else
    $isExpansion = ‘Expansion’

    return [
    ‘baseDescription’=> $isExpansion
    ];

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WPLake

    (@wplakeorg)

    Hi @dotnetdiva

    Unfortunately the code you provided wouldn’t work, as it has syntax errors.

    Please see below for a code snippet. You can use that as a base. See the “fixme” comment lines in the file, where you’d need to replace it with your values.

    Kindly note that in the Database, only the value of the selected choice is stored (from the field settings). So, if your button?group has the selected choice as ‘base: Base’, you’ll need to compare exactly with ‘base’, but not with ‘Base’.

    <?php
    
    // fixme use your field name in the quotes instead of 'base_game'
    $baseName = $_fields['base_game'] ?? '';
    
    $baseDescription = '';
    
    switch ($baseName) {
        // fixme use your target value in the quotes
        case 'base':
            // fixme use your target label in the quotes
            $baseDescription = 'Expansion';
            break;
    }
    
    return [
        'baseDescription' => $baseDescription,
    ];
    Thread Starter Kamio

    (@dotnetdiva)

    Thank you so much, got it working now!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Markup Variable for button group’ is closed to new replies.