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:

Not all field types support options.


Let’s assume we have a simple text field with the slug “myFieldSlug”.

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_values["myFieldSlug"];
echo "The second field has the value:" . $field_values["anotherFieldSlug"];
echo "The third field has the value:" . $field_values["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.

2 thoughts on “simple_fields_value

  1. SkiNNi

    $field_values = simple_fields_value(“myFieldSlug,anotherFieldSlug,aThirdFieldSlug”);
    echo “The first field has the value:” . $field_value[“myFieldSlug”];

Leave a Reply