Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know the value of a image custom field will give me the attachemnt ID. In a loop over all custom fields, how can I found out if the field is an image? And then get the image URL of the attachemnt?

My code:

$args = array( 'post_type' => array( 'my_type'), 
               'posts_per_page' => 1000, 
               'fields' => 'all' );
$loop = new WP_Query( $args );

// Custom fields being attached
$retArray = array();
while ( $loop->have_posts() ) : $loop->the_post();
    $custom_fields = get_post_custom($post->ID);  

    // Some code to get the actual image url from fields that are images:
    // MISSING!

    // Combine $post and custom field array to new array
    array_push($retArray, array('post' => $post, 'fields' => $custom_fields));
endwhile;
share|improve this question

1 Answer 1

If its your own custom post type you should know the field names? Iterate through the fields - or better just get the required field - an then use the attachment Id with wp_get_attachment_image_src.

http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

Chech the codex for further examples and Google for "WordPress custom post type fields".

share|improve this answer
    
Answers should be more than plain links. They should actually be an answer instead of a route where someone will maybe find an answer. Please help preventing link rot, edit your answer and provide the needed information that helps the OP as well as later visitors to solve their problem. –  kaiser Apr 22 at 17:29
    
Thanks rockaut, yes I do know the names of the fields. Would have loved to have them "translated" by default though. I think I can live with this though.... –  Matthias Max Apr 22 at 17:45

Your Answer

 
discard

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.