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.

How do I retrieve a custom post type image URL? All I accomplish is to get the widht and height of the image but not the actually URL.

My code looks like this and are run in the functions.php of my theme:

function fields_in_feed($content) {  
if(is_feed()) {  
    $post_id = get_the_ID();  
    $img = get_post_field('img', $post_id);

    $output = '<acfTitle>' . get_post_meta($post_id, 'titel', true) . '</acfTitle>';  
    $output .= '<acfImage>' . $img . '</acfImage>';  
    $output .= '<acfText>' . get_post_meta($post_id, 'text', true) . '</acfText>';  
    return $output;  

If I add $img[0] or $img[1] it only returns the widht and height. Nothing more is stored in the $img array, no more values.

share|improve this question
Are you sure that img is a valid field to pass to get_post_field()? –  Chip Bennett Oct 15 '13 at 13:01
add comment

1 Answer

get_post_field is function to get posts fields which are present in the posts table in the database. To get featured image of the post use get_the_post_thumbnail function.Add the below line in your code

  $output .= '<acfImage>' . get_the_post_thumbnail($post_id, 'thumbnail') . '</acfImage>';  

for more details see below link


share|improve this answer
The case is that it is an ACF (Advanced custom field) so no featured image. Any clue how I solve this? –  JohnSmith Oct 15 '13 at 13:29
add comment

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.