simple_fields_values

simple_fields_values – Get one or several repeatable simple fields values from a post.

This works the same way as simple_fields_value but it returns an array with all values since it retrieves all values from repeatable field groups.

Description

mixed simple_fields_values( string $field_slug [, int $post_id, mixed $options] )

Parameters

field_slug
A comma separated list of field slugs to get values for.

post_id
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.

options
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. So far, only a few field types support options.

Examples

Let’s assume we have a repeatable 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_values(), like this:

$field_value = simple_fields_values("myFieldSlug");
echo "The first field in this repeatable group has the value: $field_value[0]";
echo "The second field in this repeatable group has the value: $field_value[1]";

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_values("myFieldSlug,anotherFieldSlug,aThirdFieldSlug");

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>