Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called Testimonial that includes custom fields "name", "title" and "bank". I would like to display each of these items on a page. Here's what I have so far:

    <?php
    while ( $loop->have_posts() ) : $loop->the_post();
      the_title();
      echo '<div class="entry-content">';
      the_content();
      echo '</div>';
    endwhile;
    ?>

This gives me something close to what I want but I don't know how to get at the actual fields individually. How do I do that?

share|improve this question
    
How do you mean to get the fields individually? Are you looking for functions like the_tags() and the_category()? –  m0r7if3r Jan 15 '12 at 20:52

2 Answers 2

up vote 1 down vote accepted
<?php
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
  echo '<div class="custom-field">';
  echo get_post_meta( get_the_ID(), 'name', true );
  echo get_post_meta( get_the_ID(), 'title', true );
  echo get_post_meta( get_the_ID(), 'bank', true );
  echo '</div>';
endwhile;
?>

This is how you would display the custom fields below the content. I didn't test it but it should work. Hope this helps. Also read Milo's answer and read the Codex so you understand how it works.

Also it looks like you are using a custom query object ($loop), so read this article as well:

http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1

share|improve this answer

See the Custom Fields page in Codex for the various functions available to output your fields: get_post_custom, get_post_custom_values, get_post_meta, the_meta.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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