WordPress.org

Ready to get started?Download WordPress

Forums

Display a Specific Custom Field (4 posts)

  1. dcochran
    Member
    Posted 7 years ago #

    I want to be able to place a custom field (code for a linked image) before the title of the post.

    I have been reviewing the documentation page, Using Custom Fields and trying different variations.

    I can get it to display the code I want (and therefore the linked image) by using <?php the_meta(); ?>, but it also gives me the key name, which I don't want, and even though I can dispense with this (display: none) in the css, this is sloppy because it will pull out all keys and values for any custom fields. I would like to be as specific as possible, in case I want to use other custom fields for other purposes and in other places.

    So my question: What php code do I need to get it to give me only the VALUE for the key "image"?

  2. moshu
    Member
    Posted 7 years ago #

  3. dcochran
    Member
    Posted 7 years ago #

    It works great! Thanks.

  4. marketanomaly
    Member
    Posted 7 years ago #

    Use

    <?php echo get_post_meta($post->ID, 'post_image', true) ?>

    where post_image is the name of the custom field key that contains the link to your image.

Topic Closed

This topic has been closed to new replies.

About this Topic