WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display multiple custom field values with the same custom field type (3 posts)

  1. irina85
    Member
    Posted 5 years ago #

    OK, I tried the search and looked through the Codex, but couldn't resolve my issue(s).

    1.) I want to display various thumbnails with one custom field type. This is how my current code looks like:

    <a href="<?php echo get_post_meta($post->ID, "Product URL", true); ?>"><img class="side-thumbs" src="<?php echo get_post_meta($post->ID, "Product Picture Thumbnail", true); ?>" alt="<?php echo get_post_meta($post->ID, "Product Name", true); ?>" /></a>
    <a href="<?php echo get_post_meta($post->ID, "Product URL", true); ?>"><strong><?php echo get_post_meta($post->ID, "Product Name", true); ?></strong></a>

    I know that $single has to be set to false and not to true like above in my code, but when I do that I only get the text array for each custom field value.

    I figured out it's because $single is an array, but since I'm no programmer I don't know how I can change the PHP code to display all the custom field values which have the same custom field type. Can anyone help me with that? It would be really appreciated. Thanks!

  2. MichaelH
    Member
    Posted 5 years ago #

    This will give you an idea (left some echo statements in there so you can see the values):

    <?php
    $cf1values = get_post_meta($post->ID, 'cf1', false);
    echo "<pre>"; print_r($cf1values); echo "</pre>";
    if ($cf1values) {
    foreach ($cf1values as $cf1value) {
    echo '<p>for post id: '.$post->ID.' cf1 value is: '.$cf1value .'</p>';
    }
    }
    ?>
  3. irina85
    Member
    Posted 5 years ago #

    Thank you, Michael. I managed to make it work with a different approach, but your code certainly functioned for me to a certain degree as well. :)

Topic Closed

This topic has been closed to new replies.

About this Topic