{"id":1179545,"date":"2009-08-16T19:44:42","date_gmt":"2009-08-16T19:44:42","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/using-get_post_custom_values\/"},"modified":"2016-08-19T13:42:21","modified_gmt":"2016-08-19T13:42:21","slug":"using-get_post_custom_values","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/using-get_post_custom_values\/","title":{"rendered":"Using get_post_custom_values"},"content":{"rendered":"<p>Hi there.<\/p>\n<p>I am trying to build a function in my theme which collects post metadata and displays them, according to what I write in the custom field. I want to show images representing flags (for countries). Some posts must have more than one flag displayed.<br \/>\nI thought the function get_post_custom_values would be nice.<\/p>\n<p>&lt;?php get_post_custom_values($key, $post_id); ?&gt; in my theme where I want the images to show up. For each post I create a custom field named flags, and type in values like uk,dk (etc).<\/p>\n<p>And this script to associate metadata to images:<\/p>\n<p>&lt;? php<br \/>\n$uk=\/images\/uk-png;<br \/>\n$dk=\/images\/denmark.png;<\/p>\n<p>$mykey_values = get_post_custom_values(\u2018flags\u2019);<br \/>\nForeach ($mykey_values as $key =&gt; $value) {<br \/>\necho \u201c$key =&gt; $value (\u2018flags\u2019)\u201d;<br \/>\n}<br \/>\n?&gt;<\/p>\n<p>But it doesnt work. Any hints?<\/p>\n","protected":false},"template":"","class_list":["post-1179545","topic","type-topic","status-closed","hentry","topic-tag-custom-field","topic-tag-metadata"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/1179545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/1179545\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=1179545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}