simple_fields_value – Get one or several simple fields values from a post
mixed simple_fields_value( string $field_slug [, int $post_id, mixed $options] )
A comma separated list of field slugs to get values for.
The post to get the values from. Optional parameter, if left out then the function defaults to get the values for the current post in the loop.
An optional set of options as array or query string to send to field type. This is a way to send options to the field type so it can modify values before return, or modify the output in any way.
Common options are:
set to 1 to enable a extended return value
Not all field types support options.
Getting value from a single field
To get the value from this field we use the function simple_fields_value(), like this:
// Get value from a single field $field_value = simple_fields_value("myFieldSlug"); echo "The field has the value: $field_value"; // Get extended values from a single field $field_value = simple_fields_value("myFieldSlug", null, "enable_extended_return_values=1"); echo "The fields extended values are: " . print_r($field_value, true);
Gettings values from multiple fields as once
What if we have several fields we want to retrieve values from? Simple: we just add all the fields to the same functions, as a comma separated list, like this:
$field_values = simple_fields_value("myFieldSlug,anotherFieldSlug,aThirdFieldSlug"); echo "The first field has the value:" . $field_value["myFieldSlug"]; echo "The second field has the value:" . $field_value["anotherFieldSlug"]; echo "The third field has the value:" . $field_value["aThirdFieldSlug"];
The main difference between getting one field and several field is that if you only get one field it’s return value gets return immiedently, while getting several fields then you get an array in return, with each field stored in a key with it’s slug as the key.