Uses regular Custom Fields
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.
Field Type ”File” returns the file id
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:
- http://codex.wordpress.org/Function_Reference/get_post
- http://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata
- http://codex.wordpress.org/Function_Reference/wp_get_attachment_image
- http://codex.wordpress.org/Function_Reference/get_attachment_link
Show an image based on Simple Fields file
[php]
<?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 ?>" alt="An image" />
[/php]
Lämna ett svar