The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Echo values for custom fields with the same ‘key’ value

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #31181

    Hi all,

    I’m working on my first WP site that uses custom fields. I’ve created a custom field titled “Testimonials”. I have added three instances of that custom field to this page

    I’m trying to display all 3 instances of the “Testimonial” field in the sidebar. However, I can only get 1 to display.

    Any suggestions?

    Below is the code within my sidebar.

    Template Name: Testimonials

    I have not worked alot with wordpress – at all. So I might be completely wrong…

    But if it was just plain PHP, I’d say that you miss some kind of loop. A while or foreach loop would do the job.

    You only make one call to the get_post_meta function. I could imagine that there would be a function named get_post_meta_all, or something like it, that returned an array with all the values from the custom field of your choice…

    I hope you’ll figure something out :-)


    Try this – I haven’t tested it though:

    ID, 'Testimonial', true) ) : ?>


    Based on the above, I modified it to echo out the value of the ‘Testimonial’ custom field. However, I’m still only getting the first instance of ‘Testimonial’ to display. The page below has 3 instances of the custom field.

    ID, 'Testimonial', true) ) : ?>


    Im back again after a good nights sleep. I’m sorry, but I was too lazy to look this up last night.

    A quick view in the wordpress documentation revealed that my suspicion was right.

    You should not use get_post_meta(), but get_post_custom_values(). It does the same thing, but is for when you have customfields with non unique keys. It returns an array that you can throw in a foreach.

    Link to the manual page:

    Example, build on the code from the OP:

    EDIT: (I have no idea why it screwed the coloring and indexing of the code above…)


    Perfect. That worked. I really need to improve my php skills. I had read that reference in your link multiple times, but couldn’t figure out the syntax.

    Thanks for the help!


    Your welcome. Glad it worked. :-)

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.