Forums

[resolved] Custom Field, getting the propper data to display. (3 posts)

  1. mabufo
    Member
    Posted 3 years ago #

    Hello. I am trying to make use of custom fields in my blog. In my post, I have a field called: price, with a value of '$17'. I set this particular value up for testing purposes. Anyway: I want to display this meta information in two places, the first place is where the post appears on my index.php page, and the second is below my actual post in the single page (single.php) thing. I am trying to somewhat hard code this into my theme, but I'm running into trouble.

    Right now, on the index I have this code trying to display the meta information.
    <strong>Price: </strong> <?php echo get_post_meta($post_id->ID, "price", $single = true) ?>
    As far as I know this looks fairly correct. However, I'm going to assume that the code is not properly grabbing a post id to retrieve meta data from. my question is, how do I fix it so it outputs my price value stored?

    Let me know if I should post more information.

    EDIT: Code looks like htis now: <strong>Price: </strong> <?php $price = get_post_meta($post_id->ID, "price", $single = true); echo $price; ?>.

  2. mabufo
    Member
    Posted 3 years ago #

    Okay fixed:

    Price: <?php $price = get_post_meta($post->ID, 'price', $single = true); ?> <?php echo $price; ?>

  3. Dgold
    Member
    Posted 3 years ago #

    Good job :)

    Custom fields is a powerful feature, more people need to use it like this.

    I think there was a way to write the php code like you were before (all in one), there might just be a little syntax thing to fix, but if the 2nd way works that's fine too.

Topic Closed

This topic has been closed to new replies.

About this Topic