- Does Simple Fields use regular Custom Fields?
- Why does the “File” field type return an id, and not the name of the file?
- So how do I show an image based on a Simple Fields file field then?
- Can I sort posts based on a Simple Fields field?
- Why does dropdown return so wierd values?
Does Simple Fields use regular Custom Fields?
Yep. The selected values in a Simple Fields-box is stored as regular WordPress Custom Fields. That means you can use functions like get_post_meta and query_posts. To see the name of they custom field click the “show custom fields keys”-link that are available on the post edit screen.
Why does the “File” field type return an id, and not the name of the file?
When you get the saved value for a field of type “File” you only get the id of the attachment, and not for example the path to the file. That’s not a bug. It’s a feature.
Since I don’t know what the developer wants to do with a file (show it? print the filename? output the dimensions?) the plugin only returns the file ID, and then you can use WordPress own functions to fetch more info about the file.
Some useful functions to use in this case:
So how do I show an image based on a Simple Fields file field then?
One way to do it is like this:
<?php $image_id = get_post_meta(get_the_ID(), "_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0", true); $img_src = wp_get_attachment_url($image_id, 'thumbnail'); ?> <img src=<?php echo $img_src ?> />
Can I sort posts based on a Simple Fields field?
Why does dropdown return so wierd values?
It may seem so, but it’s actually pretty smart. @todo: explain why the hell that is