Trouble displaying multiple values of a custom field key
-
Hi, I’m using this tutorial to try to list multiple values of one custom key under each post. I feel like I’m pretty close but I’m not quite there.
It seems to be working fine on posts that have just one value for each key. See some posts on this page of my site for an example of where things are working and not working. This entry with only one value is fine but this one, which is supposed to have 3 values listed, only has one listed, plus the CSS formatting which I used to hide the date of the post, the category and the author is now not working for that post only. You can see below the notes that “March 22, 2011Uncategorizedfamily, Joan, movies, travelThe Diarist” is showing there. Only the tags should show under each post, as they do with all other posts that only have one value.
Here’s the code I’ve used:
<?php $my_notes = get_post_meta($post->ID, "Notes", false); if ($my_notes[0]=="") { ?> <!-- If there are no custom fields, show nothing --> <?php } else { ?> <div class="MyNotes"> <h3>Notes:</h3> <?php foreach($my_notes as $my_notes) { echo '<blockquote><p>'.$my_notes.'</p></blockquote>'; } ?> </div> <?php } ?>
Notes is my key. $my_notes is what I’ve chosen as the variable that will store the value of each custom field, as he says in the tutorial. Can I really just choose anything for that? This code is within its own div between the entry-content and the entry-meta sections (not within them). I’m using a child theme of the Twenty Thirteen theme.
Can anyone see what I’m doing wrong here? Any help would be greatly appreciated. Thanks!
- The topic ‘Trouble displaying multiple values of a custom field key’ is closed to new replies.