• Resolved tomslattery

    (@tomslattery)


    Hiya,

    I am trying to display a custom field in my post. From what I’ve read, the ‘get_meta’ code needs to be placed in the Loop. Problem is, I haven’t seen an example anywhere where they say “edit this file, place the code here.” For simplicity, I am working with the WordPress standard template. My custom field is named “list_price”. All I want to to is have that value show up the post. What code do I put where?

    Thanks!
    ~TPS

Viewing 3 replies - 1 through 3 (of 3 total)
  • Something like this:

    <?php //get list_price (custom field) ?>
    <?php $list_price = get_post_meta($post->ID, 'list_price', true); ?>
    <?php echo $list_price; ?>

    Put that somewhere in your loop, between the “if has post, while has posts, the post” and before the “endwhile”.

    Thread Starter tomslattery

    (@tomslattery)

    That worked. Thanks!

    Thread Starter tomslattery

    (@tomslattery)

    I’m going a layer deeper: I would like to lead into the data with “List Price: “

    So I did this:

    <span style=”font-weight: bold”>List Price:</span>
    <?php //get list_price (custom field) ?>
    <?php $list_price = get_post_meta($post->ID, ‘list_price’, true); ?>
    <?php echo $list_price; ?>

    Only problem with that is that every post will have that text in it whether or not the data shows up.

    Is there a way to say “only display this text if there is data there”?

    Thanks!
    ~TPS

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Displaying Custom Fields’ is closed to new replies.