• hello,

    i added custom field “myname” and i want to display that in the post.
    i looked at some examples but its not working.

    i have tried:

    <?php get_post_custom_values($myname); ?>

    this custom field is come after “Name:” (title) so i need a code to display both, only if there is a value in the custom field.
    thanks for help!

Viewing 1 replies (of 1 total)
  • Chad

    (@lynneandchad)

    Assuming I’m understanding your question right, something like this should work:

    global $post;
    //get your custom field
    $myname = get_post_meta( $post->ID, 'myname', false );
    //display content if the field is available
    if ($myname) {
      echo "Name: " . the_title();
      echo $myname;
    }

    get_post_meta(); needs the id of the post, followed by the name of the key you created (in quotes) and the ‘false’ to specify that you want the result in a string that you can print out, rather than an array.

    Also, you should make your meta key more unique – give it prefix with the initials of your name or your site. That way themes/plugins using their own custom fields will be less likely to use the same name.

    For example, ‘rregev_myame’ or something equally unique. ??

Viewing 1 replies (of 1 total)
  • The topic ‘show custom fields in the post’ is closed to new replies.