Support

Account

Home Forums General Issues need to select first item in meta_value array to sortby Reply To: need to select first item in meta_value array to sortby

  • Hi @crushdg

    It is important that you always debug your code. You can do so like this:

    
    <?php 
    
    $arr = get_field('application_type', $post->ID);
    echo '<pre>';
    	print_r( $arr );
    echo '</pre>';
    die; 
    
    ?>
    

    This will show you the data you have. When you see ‘array’, it means that the variable is an array, not a string. Therefore, it can’t be echo’ed. Please research arrays on google to learn more.

    A checkbox will always return an array because you can select multiple values.

    To get the first checked value fromt he array you can do so like this:

    
    $arr = $arr[0];
    

    Does this help?

    Thanks
    E