WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Calling image from pod field (6 posts)

  1. Olly - OWMC
    Member
    Posted 1 year ago #

    Follow up to my previous post, this time to call an image from a pod field.

    Using <?php echo get_post_meta( 56, 'photo', true ); ?> (where 'photo' is the field in my pod where I upload an image) does not display the image. It just displays the word “Array” where the image should be. I would like to know why this is and how to rectify. Any help really appreciated.

    Ideally I would like to display the image as a background image, I guess by putting an inline css rule.

    Here's my code so far: http://pastebin.com/RkZ6hRg5

    http://wordpress.org/extend/plugins/pods/

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 1 year ago #

    get_post_meta( 56, 'photo', true ) will return an a array of the file information. Try this instead:

    <?php echo pods_image( get_post_meta( 56, 'photo', true ), 'thumbnail' ); ?>

    You can customize 'thumbnail' to be whatever size of the image you want it to be.

  3. Olly - OWMC
    Member
    Posted 1 year ago #

    Thanks Scott! That's displays the image perfectly.

    Just one thing though, I'm trying to get it to load as a background image to a div ("featuredwork"). But my level of php currently fails me. I've tried:

    <div class="featuredwork" style="background:url('<?php echo get_post_meta($post->ID, 'main_photo', true); ?>');>

    As well as declaring the variable $bg:
    <?php $bg = wp_get_attachment_image_src(get_post_meta($post_id, 'main_photo', true ), 'original');?>
    and calling it as so:
    <div class="featuredwork" style="background:url('<?php echo $bg?>');">

    But neither works. Any pointers?

  4. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 1 year ago #

    Output an image:

    echo pods_image( get_post_meta( 56, 'photo', true ), 'original' );

    Output an image's URL:

    echo pods_image_url( get_post_meta( 56, 'photo', true ), 'original' );

    So for your needs:

    $bg = pods_image_url( get_post_meta( 56, 'photo', true ), 'original' );

  5. Olly - OWMC
    Member
    Posted 1 year ago #

    perfect. can i buy you a beer ? do you have a donations link?

  6. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic