Support

Account

Home Forums Front-end Issues how to get selected select label

Solving

how to get selected select label

  • sorry for double post . my previous post is this. now facing new issue. i tried many way but can not find out solution.

    now i want to display selected select label also. bellow is my full code

     <?php 
    	 $value = $_GET['value']; // get value of selected choice.
    $args = array(
        'meta_key' => 'property_type',
        'order'  => 'ASC',
        'meta_value' => $value
    );
    
    $the_query = new WP_Query( $args ); ?>
       <?php
      
      $field = get_field_object('property_type');
    $value = $_GET['value'];
    $label = $field['choices'][ $value ];
    
       ?>   <h1><?php echo $label; ?></h1>  
        <ul>
         
          <?php if ( $the_query->have_posts() ) : ?>
          <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	  
          <li><a href="<?php the_field('property-flyer'); ?>"> <?php the_title(); ?>        </a></li>
         
    	   <?php endwhile; ?>
          <?php wp_reset_postdata(); ?>
          
          <?php endif; ?>

    i tried also this way to get label but not coming

    <?php
      
      $field = get_field_object('property_type');
    $value = $_GET['value'];
    $label = $field['choices'][ $value ];
    
       ?>   <h1><?php echo $label; ?></h1> 
  • Hi @pagol

    I would recommend that you try using get_field() function instead of using the $_GET.

    The code will look something like this:

    $field = get_field_object('field_name');
    $value = get_field('field_name');
    $label = $field['choices'][ $value ];
    
    ?>
    <p>Color: <?php echo $label; ?></p>
  • Hi @acf-support I would like to know how you can I pass “select field inside a repeater field” to get_field_object ?

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

You must be logged in to reply to this topic.