0
votes

I'm working with Wordpress 3.5.2 and plugin Advanced CUstom Fields 4.1.8

I have a group of fields (called "P") and some fields. I want to retreive all data from a specific select field, and I found some code in the plugin documentation:

$values = get_field('field_519a0279bc93e'); if($values) {

foreach($values as $value)
{
    echo '<li>' . $value . '</li>';
}

echo '</ul>';

}

In $values, getting two different select fields In a case I get a string and in another a boolean. I supposed is so simple, but I can't find the solution.

Thanks in advance.

1
I have experience in Advanced Custom Fields but don't quite understand your question. Are you simply trying to output the values for the specified custom field? - Joe Buckle
Yes, only the values inserted as options in the select field: "male", "female". Thanks in advance. - user1432966
so in the admin, the custom field specifies one of 2 values. Male or female. I'm guessing on the front end it will say something like sex: male is that right? If so I'll post a suggestion - Joe Buckle
Yes. The result of "echo $values;" shows: "Male", only one value, and not an array with the two values, as it says in the plugin documentation. - user1432966

1 Answers

0
votes

It is important to understand that when using the Advanced Custom Fields plugin all this does is create an easier method for admins to add custom fields for posts, so the WordPress get_post_meta() still applies.

Say you've created a custom field called 'sex' and you've assigned a dropdown or radio buttons to it and you wanted to display what this value in the post or the loop, you would do the following.

Outside the loop

 ## Returns sex custom field value for current page ID
 $sex = get_post_meta( get_the_ID, 'sex', true);

Inside the loop

## Returns sex custom field value for current loop iteration
global $post;
$sex = get_post_meta( $post->ID, 'sex', true);