WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm much of a php-noob but have this idea of a loop for my site. I have the idea behind it but maybe you have an idea how to put this into code:

$customfield = get_specific_customfield

if $custom-field is = not empty
echo 'custom-field-input" class="'


echo '`<?php echo $thumbnail_src[0]; ?>" class="fancybox`'

(I have to integrate the fancy-box stuff to control how the input will be displayed)

share|improve this question
whats the question? – Bainternet Aug 15 '11 at 11:29
»...maybe you have an idea how to put this into code« – juliusk Aug 15 '11 at 16:10
up vote 0 down vote accepted

To get a value of a single custom field use

    $post_id = $post->ID;
    $key = 'value';  // change value to what custom field you are looking for
    // To retrieve only the first value of given key
    $customfield = get_post_meta($post_id, $key, 'true');
    // To use as default
    $customfield = get_post_meta($post_id, $key);
    // Then check what you got
    <img class="thumb" src="<?php echo get_post_meta($post_id, $key, true) ?>" alt="<?php the_title(); ?>" />

    echo 'whatever you want to show by default';

For further reading goto codex

Hope it helps you

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.