Tips and Tricks

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:

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]

Kommentarer

6 svar till ”Tips and Tricks”

  1. Profilbild för Rory

    Hi there, great plugin.

    I have no php experience. Can you give me an example of how I can use the ”File” field type to add a downloadable pdf attachment. What do I need to add to my template?

    Thanks.

  2. Profilbild för Leo
    Leo

    Great post. It would be nice to have cretain checkboxes set as a group, like gym amenities: Circuit Training, Boxing etc, all under amenities.

    Thanks,

  3. Profilbild för norty
    norty

    Pär i don’t know weather this is a bug or not, but NONE of the files i upload throu a SimpleFields button gets attached to the current post. this is for file-field but also for the tinyMCE’s Media buttons.
    Both bring up the WordPress (NextGenGal.) Upload Dialog and files get stored correctly to the Mediathek. I can even choose files from the Mediathek to insert in the post or field, but there is no ’Gallery’-Tab. So i could not insert a gallery to the tinyMCE field?? …and i can’t use WP-functions for post-attachment to get e.g. the url of the thumbnail-size of an image?
    Would be so great to have it. Is this intended to (not) work like this?
    I’ll have a look at the plug-in’s code now maybe i can find something.
    Thanks a lot!

  4. Profilbild för Kevin
    Kevin

    Very Easy Display on Posts using shortcodes using a separate plugin:

    Custom fields shortcode

    Syntax in post editor:

    [cf]_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0[/cf]

  5. Profilbild för Dennis Rivers
    Dennis Rivers

    SHORT CODES FOR INSERTING SPECIFIC SIMPLE FIELDS INTO PAGES

    Right now Simple Fields does not have its own shortcode scheme, so here is a workaround.

    For my site, I need to be able to place any of the Simple Fields anywhere on a page using the page editor, not by editing the template. I succeeded in doing that by using another plugin, ”Shortcode Exec PHP” . ”internship” is one of my Simple Fields. In Shortcode Exec PHP I created a code block named [display_internship] and put the following code (from the Functions page of this site) into it:

    $tempvariable = simple_fields_get_post_value(get_the_ID(), ”internship”, true);
    echo ”$tempvariable”;

    Now I can put [display_internship] into the text of the page. For this purpose, I have found that Shortcode Exec PHP works better than Hana Code Insert. For reasons I do not understand, Shortcode Exec PHP displays Simple Fields text using the page’s stylesheet, while Hana Code Insert does not.

    For WordPress and PHP Newbies: The one thing you will need to change to use this workaround in the instance of ”internship” in the code. Replace ”internship” with the name of one of your Simple Fields. Keep the field name quoted.

  6. Profilbild för Putu Mutukas

    Hello,

    Is it possible to insert multiple images (i have a image custom field but clicking ”Add” for each picture is quite time consuming). I’ve tried the plugin Faster Image Insert but to successfully insert the pictures i’d need to bind the pictures with custom fields for example or is there a good way to automate the Add link pressing ?

    With best regards,
    Putu