WordPress.org

Support

Support » Plugins and Hacks » Custom Field Template » [Plugin: Custom Field Template] How to get the Key to Show?

[Plugin: Custom Field Template] How to get the Key to Show?

  • Kinda a noob question but when it comes to this plugin and custom fields that is what I am.

    How do I get the Key to show with the value?

    Here is the Code I am using in my page template: <?php echo get_post_meta($post->ID, 'Key Goes Here', true); ?>

    I want the key to show up with the value but if there is no value then I don’t want anything to show up. Is this possible? Thanks!

    http://wordpress.org/extend/plugins/custom-field-template/

Viewing 2 replies - 1 through 2 (of 2 total)
  • You already know what the key is, in order to look up the value. Is the key hard coded in apostrophes or in a variable? If hard coded you can do it like this:

    <?php if ( $value = get_post_meta($post->ID, 'Key Goes Here', true) ) {
      echo 'Key Goes Here' . ' value = ' . $value;
    } ?>

    If key is in a variable

    <?php if ( $value = get_post_meta($post->ID, $key, true) ) {
      echo $key . ' value = ' . $value;
    } ?>

    Change the echo statement to format however you want the output.

    Hey Steve,
    Thank you for the response! I see you are from Ashland, I am from Portland!

    The hard coded snippet is just what I was looking for. I wanted to make it work when there was a value to the key on the corresponding page and disappear when there is no value to the key. Worked perfectly! Hopefully this will help someone else out along the way as well.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Custom Field Template] How to get the Key to Show?’ is closed to new replies.
Skip to toolbar