WordPress.org

Forums

Simple Fields
Adding image through simple fields displays a number (6 posts)

  1. phantomdentist
    Member
    Posted 4 years ago #

    Awesome plugin.

    Have an issue when using a file attachment field to add an image. Just 1 image, its not a repeatable field. I'm using

    <?php $portfolioThumb = simple_fields_get_post_value(get_the_id(), array(2, 4), true);
    	echo "<span class='meta-value_portfolio-thumb'>$portfolioThumb</span>";?>

    Instead of showing the image the images database number is displayed.

    Looking at the database I see the meta_id, post_id and the following simple fields key and meta

    _simple_fields_fieldGroupID_2_fieldID_4_numInSet_0 192

    Any ideas?

    Thanks

    http://wordpress.org/extend/plugins/simple-fields/

  2. Pär Thernström
    Member
    Plugin Author

    Posted 4 years ago #

    It’s actually meant to be like that. 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.

    Useful functions include:

    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

  3. Rob Beschizza
    Member
    Posted 4 years ago #

    Quick illustration of how to show an image with Simple Fields:

    <?php 
    
    $selected_value = simple_fields_get_post_value(get_the_id(), "Your Image Field Name", true); 
    
    $theImageURL = wp_get_attachment_url($selected_value);
    
    echo '<img src="'.$theImageURL.'">';
    
    ?>
  4. Pär Thernström
    Member
    Plugin Author

    Posted 4 years ago #

    Thank you very much Beschizza for the example!

  5. TheJacob
    Member
    Posted 4 years ago #

    Thanks Beschizza, very helpful. I have another question though.

    How do I add dimension "rules" to your code? You know, like when you pull a featured image from your post with this:

    <?php 
    
    	if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(220,180), array("class" => "alignleft post_thumbnail")); } ?>

    I want to use the Simple Fields plugin for thumbnail images.

    Thanks.

  6. TheJacob
    Member
    Posted 4 years ago #

    Never mind, I just did this:

    <?php
    $selected_value = simple_fields_get_post_value(get_the_id(), "Thumbnail 1", true);
    $theImageURL = wp_get_attachment_url($selected_value);
    echo '<img src="'.$theImageURL.'" width="75" height="75">';
    ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Simple Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic