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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.