Extended Return Values

Previously, the file field for example only returned the file id, and then you had to do all the hard work yourself: getting the name of the file, the path, check if it was an image or not, and so on.

With Extended Return Values things gets much simplier: just click “Enable Extended Return Values” in the settings for a field and then magically/automatically you will get an array with useful values as the return value instead.

The contents of this array depends on what field you are using. Please see each field type for more information about their return values.

Example


// Without Extended Return Values
$file_id = simple_fields_value("my_file_slug");
$image = wp_get_attachment_image($file_id, "thumbnail");
echo $image;

// With Extended Return Values
$file_info = simple_fields_value("my_file_slug");
echo $file_info["image"]["thumbnail"];

How to enable

There are 2 ways to enable Extended Return Values:

  1. Tick the “Enable Extended Return Values”-checkbox for a field and it will always return the Extended Values.
  2. Use the API to selective enable Extended Return Values:


// Add the extended_return-argument to all fields
simple_fields_value("mySlug", $postID, "extended_return=1")
simple_fields_value("mySlug,mySlug2", $postID, "extended_return=1")

// Add only to a specific field
// In this example only the field with slug "mySlug2" will have extended return values

simple_fields_value("myFirstSlug,mySlug2", $postID, "mySlug2[extended_return]=1&mySlug2[anotherArg]=1")

Field Types that support Extended Return Values

The Extended Return Values are available for the following field types:

Note: this feature was added in version 1.0.3.

Leave a Reply