Skip to content

Instantly share code, notes, and snippets.

@bonny
Created October 8, 2012 09:16
Show Gist options
  • Save bonny/3851566 to your computer and use it in GitHub Desktop.
Save bonny/3851566 to your computer and use it in GitHub Desktop.
Simple Fields getting values
/**
* Gets a single value.
* The first value if field group is repeatable
*
* @param string $field_slug
* @param int $post_id ID of post or null to use current post in loop
* @param array $options Array or query string of options to send to field type
* @return mixed string or array, depending on the field type
*/
function simple_fields_value($field_slug = NULL, $post_id = NULL, $options = NULL) {
/**
* Gets all values as array
* @param string $field_slug or comman separated list of several slugs
* @param int $post_id ID of post or null to use current post in loop
* @param array $options Array or query string of options to send to field type
* @return mixed string or array, depending on the field type and if first arg contains comma or not
*
* Example output if field_slug contains comma = get serveral fields from a repeatable field group
* Array
* (
* [0] => Array
* (
* [image] => 1156
*
[text][/text]=> Text 1
* [link] => /hej/
* )
*
* [1] => Array
* (
* [image] => 1159
*
[text][/text]=> Hej svejs i ditt fejs
* [link] => /hopp/
* )
*
* Example output if field_slug with no comma:
* Array
* (
* [0] => Text 1
* [1] => Hej svejs i ditt fejs
* [2] => Lorem ipsum dolor sit amet
* )
*/
function simple_fields_values($field_slug = NULL, $post_id = NULL, $options = NULL) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment