Hey I'm new to WordPress. I've looked at the codex and other topics here, I just don't get how to display my custom field, which I have set in the area under my post editor. The name is MyField and the value This is my custom post text.

Now I want to include my field into the category loop, so it shows up instead of the standard excerpt.

<?php the_meta(); ?> shows obviously all custom fields, that is not what I want.

I´ve tried to include <?php get_post_custom_values('MyField'); ?>, which changed nothing, do I have to do something with this after that like calling it? How can I do that?


Use: get_post_meta():

if ( get_post_meta( $post->ID, 'MyField', $single=true ) ) {
    echo get_post_meta( $post->ID, 'MyField', $single=true );

Hope below will help For user meta:

  $user_id = 9;
  $key = 'last_name';
  $single = true;
  $user_last = get_user_meta( $user_id, $key, $single ); 
  echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: ' . $user_last . '</p>'; 

For Post meta:

$key_1_value = get_post_meta( get_the_ID(), 'key_1', true );
// check if the custom field has a value
if( ! empty( $key_1_value ) ) {
  echo $key_1_value;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.