• Hi there.

    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.
    I thought the function get_post_custom_values would be nice.

    <?php get_post_custom_values($key, $post_id); ?> 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).

    And this script to associate metadata to images:

    <? php
    $uk=/images/uk-png;
    $dk=/images/denmark.png;

    $mykey_values = get_post_custom_values(‘flags’);
    Foreach ($mykey_values as $key => $value) {
    echo “$key => $value (‘flags’)”;
    }
    ?>

    But it doesnt work. Any hints?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ThorHammer

    (@thorhammer)

    bump..?

    Thread Starter ThorHammer

    (@thorhammer)

    Never mind, I found a solution.

    ?php $languages=get_post_meta($post->ID,"languages",false); ?>
    <?php foreach($languages as $language) {
    echo "<img src=\"".$language."\" />

    The only down thing is that I have to enter a custom field “languages” several times with the full URL-path to the images. But, it works, and I am happy. Hope someone else in need of using custom fields are reading this short post.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using get_post_custom_values’ is closed to new replies.