Support

Account

Home Forums General Issues ACF post selected labels list in WP_Query

Solved

ACF post selected labels list in WP_Query

  • Hi! 🙂

    I have an archive page that shows certain posts and want to echo a list of selected ACF labels (not values) for each specific post.

    I`ve got this in the loop:

    <?php $field = get_field_object('custom_field_name'); if( $field['choices'] ): ?>
    
    <ul>
        <?php foreach( $field['choices'] as $value => $label ): ?>
            <li><?php echo $label; ?></li>
        <?php endforeach; ?>
    </ul>

    This however shows all the possible labels to select (not really the ones that are selected for the specific post).

  • 
    
    <?php $field = get_field_object('custom_field_name');
    
    $value = $field['value'];
    
    if( $value ): ?>
    <ul>
        <?php foreach( $value as $label ): ?>
            <li><?php echo $field['choices'][ $label ]; ?></li>
        <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF post selected labels list in WP_Query’ is closed to new replies.