• Hey,

    New to WordPress, (and PHP) and I’m having some trouble with custom fields, hopefully you guys can help me with it.

    I’m trying to create a fancy-box image gallery with custom fields, but I can’t find info anywhere that shows me how to combine field values into one statement.

    For example, I have these two values:
    1) Thumbnail = image_thumb.jpg
    2) Full-size = image.jpg

    I’m using the following code:

    <?php
    $image_path = wp_upload_dir();
    $custom_path= $image_path['baseurl'].'/'.$post->post_name;;
    
    ?>
    <?php $thumb = get_post_meta($post->ID, 'Thumbnail', false); ?>
    <?php $full_size = get_post_meta($post->ID, 'Full_size', false); ?>
    <?php foreach($thumb as $thumb) {
    echo '<li><a class="zoom1" href="'.$custom_path.'/'.$full_size.'" rel=""/><img src="'.$custom_path.'/'.$thumb.'" /></a></li>';
    } ?>

    It loops through each thumbnail key and shows the thumbnail image just fine, but puts the full-size image link as an array. (http://PATH/wp-content/uploads/POSTNAME/Array).

    Can someone please show me how I would add the full-size image in there so that the full line of code looks like this?:
    <li><a class="zoom1" href="http://PATH/wp-content/uploads/POSTNAME/full-size.jpg" rel="POSTNAME"/><img src="http://PATH/wp-content/uploads/POSTNAME/full-size.jpgthumb.jpg" /></a></li>

Viewing 3 replies - 1 through 3 (of 3 total)
  • If there is only one full_size image for the posts, I think you need to change this:

    <?php $full_size = get_post_meta($post->ID, 'Full_size', false); ?>

    to this:

    <?php $full_size = get_post_meta($post->ID, 'Full_size', true); ?>

    Thread Starter dbwieler

    (@dbwieler)

    Thanks for the reply.
    I understand that, it’s the combining of two different custom fields that I can’t get.

    I need to pull 2 different custom fields into one foreach or while statement, but I can’t figure it out.

    Are you saying that there are multiple thumbs and multiple full_size for one post?

    If so, I don’t know of any way to match them up.

    If there are multiples, you might consider putting both the thumb and the full_size in one custom field separated by a comma and splitting them in the foreach loop. That way the pairs would always be together.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Multiple custom field values in one’ is closed to new replies.