Support

Account

Home Forums General Issues Hao can i create a dropdown list from the following ACF?

Helping

Hao can i create a dropdown list from the following ACF?

  • Hey Communnity,

    how can I get a dropdown list from the following ACF?

    
    <?php $filament_checked_values = get_field( 'filament' ); ?>
    <?php if ( $filament_checked_values ) : ?>
    <?php foreach ( $filament_checked_values as $filament_value ): ?>
    <?php echo esc_html( $filament_value ); ?>
    <?php endforeach; ?>
    <?php endif; ?>
    

    # # # # # # # # # # # # # # #

    
    <fieldset data-css-form="group">
    <label data-css-form="label" for="printer-filament">Filament</label>
    <?php
    $filament_checked_values = get_posts( array(
    'post_type' => '3d_drucker',
    'meta_key' => 'filament',
    'hide_empty' => false,
    ) );
    ?>
    <select data-css-form="input select" id="printer-filament" name="printer-filament">
    <option>Select filament</option>
    <?php foreach($filament_checked_values as $filament_value) : ?>
    <option value="<?= $filament->term_id; ?>"><?= $filament_value->name; ?></option>
    <?php endforeach; ?>
    </select>
    </fieldset>
  • This: $filament->term_id; doesn’t seem to make any sense. There is no $filament variable (you probably mean filament_checked_values?) and before you can get a term ID you need to get the terms associated with a post.

    But other than that, if your $filament_checked_values contains an array or object, you should get a dropdown list alright.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Hao can i create a dropdown list from the following ACF?’ is closed to new replies.