Functions
There are some functions available to help you get the selected/entered values in a post:
simple_fields_get_post_value
/** * get all values or just the from a field in a field group * @param $post_id * @param $field_name_or_id name as string or field group id and field id as array. * for example array(3,2) to fetch field 2 from field group 3 * @param $single bool return a single (the first) value or all values (as array) * @return string or array */ simple_fields_get_post_value($post_id, $field_name_or_id, $single = true)
simple_fields_get_post_group_values
/** * get all values from a field group * @param int $post_id * @param name or ir $field_group_name_or_id * @param bool use_name return array with names or id as key * @param int $return_format 1|2 * @return array */ simple_fields_get_post_group_values($post_id, $field_group_name_or_id, $use_name = true, $return_format = 1)
simple_fields_get_all_fields_and_values_for_post
/** * fetch all information about the field group that a post has * returns connector structure, field groups, fields, and values * well.. everything! it's really funky. * return @array a really fat one! */ function simple_fields_get_all_fields_and_values_for_post($post_id)
Most used by myself is the following one. It returns all field groups and all the fields in a nice and easy to use array.
$values = simple_fields_get_post_group_values($post->ID, 1, false, 2);
Hej Pär, tack för en mycket intressant plugin!
I’ll post in English in case it helps anyone else! I’m pretty rubbish at PHP, am still learning all the time, but I can’t figure out from the above examples how to reproduce the content I added in the simple fields on my site.
I have the ID of the post ok, I think I understand the field name idea ok but am a little confused by what to enter in the $single parameter..
Where should I add the code? Does it have to be within the loop? I’d really appreciate a practical example for non-coders like myself!
Tack i förhand!
Hi there! Glad that you find my plugin interesting!
I now that the documentation pretty much sucks right now.
Hope this helps anyway:
the single argument should be true, unless you have a field group that is repeatable.
And you should most likely be using the functions within the loop.
I will try to update the documentation a bit with some examples during next week. Check back then!
Okay – clueless about php but with documentation I’ve been able to get alternate plugins working easily. Would love to use this plugin but like the last commenter I’m a bit lost on how to implement the fields. I think I need to know what coding would go in my functions.php file (if something is necessary there) and what coding needs to go in my template files to call the custom fields. Any example would be appreciated no matter how simple.
Okay I think I understand this now. If I had a simple field I named Heading I would put something like this in my template file to pull the field:
ID, ‘Heading’, true);
echo ”$heading”;
?>
Let me know if I’m missing something or if there is an easier way to do this.
whoops. stripped out the code
Let’s see if I have more success
Something like this would get the first value from the field ”Heading”:
< ?
$header = simple_fields_get_post_value(get_post_ID(), "Heading", true);
echo "$heading";
?>
yep – exactly! well you mistyped $header instead of $heading but thats basically the gist of it. I’m pulling my simple fields now and its working beautifully. Big fan of this plugin and how cohesive it looks from a user’s perspective.
ONe thing to mention – I am having a bit of trouble with p tags and breaks being stripped from the simple fields that are html text edit boxes. I’m not sure if that is an issue others are having.
Good to hear!
I’ll take a look at the html-thingy. Haven’t had the time to use it so much myself yet! :/
This functions don’t work for me. I don’t know how to show the boxes on my posts, and i really need it urgently.
This plugin is perfect for my proyect, but i can’t use it. The group box appear at my admin panel (when i edit a post or a page), but when i publish the post, no appear.
Can you help me?
I know that the documentation/tutorials is far from complete right now. However.. to show your boxes on your blog/page you need to edit your template and add some php-code there. More examples will come ”soon”…
Thank you!!! I’ll waiting for your tutorials, i really need it just now XD.
This plugin is awesome! I have one question, however. Once I ad my resource links to a post, how do I delete one of them? For example, I may add 15 repeating resource links to a post and sometime in the future need to delete 5 of them. Is this possible?
Yes, that’s possible. In repeatable fields groups, each added field group will have a small ”trash can” that you can click to remove that individiual field group.
Hey small problem,
first of all i love this plugin
I created my field and it works and then i entered the code another commenter used and everything seems going well but i come across this error on my page…
Fatal error: Call to undefined function get_post_id()
Ah, I think I wrote the comment without testing the code first – same thing I am doing right now..
I think that ”get_post_id()” should be ”get_the_ID()”, that is a WordPress function documented here: http://codex.wordpress.org/Function_Reference/get_the_ID
Let me know if works!
Hi,
Is it possible to get an array of pages having a specific field? (eg: i want to display all the pages having ‘menu = 1′)
Thanks
Yes, you should be able to do that with query_posts and the parameter for custom fields.
When you edit a post, click ”Show custom field keys” to see what meta_key your field has, then use this key as a parameter for query_posts, like described in the wordpress documentation:
http://codex.wordpress.org/Function_Reference/query_posts#Custom_Field_Parameters
Good luck!
Hi Pär,
I’m having trouble getting my head around on how to integrate repeating fields into a template.
If I wanted to do a series of repeated elements like such
ZZZZ
Where XXXX is an uploaded image GroupID_3_fieldID_1
YYYY is text GroupID_3_fieldID_2 and
ZZZZ is text GroupID_3_fieldID_3
How would I go about doing that?
(Thanks for a great plugin, by the way)
Cheers,
Nathan
Hi Nathan,
if I understand your problem correctly you should be able to do this with the function
simple_fields_get_post_group_values().
Something like this:
$arr = simple_fields_get_post_group_values(get_the_id(), 3, true, 2);
and then
foreach ($arr as $key => $val) {
echo ”key $key has value $val”;
}
and then modifying the loop to create a link.
Can you show how to make a list when i want to show the values. I started like this:
$selected_value = simple_fields_get_post_value(get_the_id(), ”bereiding”, true);
echo ”$selected_value”;
But i don’t now how to get the inside of this
This head to show ol in front of $selected_value en /ol behind it.
And the i want to know how to make the li work
Love the Simple Fields plugin, but I’m running into an issue. I am trying to pull a field with the field name, but I am getting a ”Undefined variable: field_group_id” error when I run it. If I change the name to the array equivalent it works, but I have a situation that requires me to use the name and not the ID array. Please help!
Thank you,
Lucas
Pär
super nice plug in.
works smashingly.
I have added a new textarea to posts and have enabled the rich text editor. However when adding media to the Word Press default content editor I can not ”show” individual media settings. I am able to use the ”show all” to get at the settings however when i click ”insert” the media gets inserted in the custom simple field as opposed to the default WP content editor. So essentially i have to turn off Simple Fields rich text editor. Something I am doing wrong?
cheers from the states.
Peter
Hi there!
I want to show the images uploaded through simplefields plugin.
I got the custom field name: ‘_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0′
How can I insert it in the theme? what’s the code?
I tried these one without a proper success…
<img src="ID, ”_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0″, true); ?>” />
Thank you.
Daniele
ehrm.. sorry but the codes I posted were modified by this post!
so then, I could show my images into the theme?
Thank you in advance!
Daniele: I’ve updated this page with some info about getting a simple fields file into an img-tag:
http://eskapism.se/code-playground/simple-fields/tips-and-tricks/
Does this help you?
Par,
GREAT plugin!
I am trying to display an image using this code:
<img src="” alt=”An image” />
It displays the file name, but not the image.
What am I doing wrong?
Thanks!
Par,
It seems that the code was stripped out when I posted. Let me try again.
It displays the file name, but not the image.
What am I doing wrong?
Thanks!
You need to use wp_get_attachment_image_src . The function wp_get_attachment_image will return a complete img src element.
Actually, something like this should work:
$src = array_shift(wp_get_attachment_image_src($image_id, ”full”));
Hi
Thank you very much for created such Great plugin!
But I have some problems and I can find a solution.
So I’ve created several drop-down menus for the posts, and I have to build a search engine, which can sort search by the drop-down menus got from the simple fields drop-down menus.
I can find the solution how to get this info into simple array for each drop-down menu.
Best Regards!
Bobby
Great plugin!!
I need to get the name(not the value but the name) of a checkbox field, i’ve tried with print_r(simple_fields_get_all_fields_and_values_for_post($post->ID)) , i can see the name ,but the array is too big!