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.

Which plugin or code I need to make it show me a list with the posts that don't have featured image or is broken(the featured image doesn't exist anymore)?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

In form of a shortcode:

add_shortcode('nofeatures', 'wpse_51768_shortcode');
function wpse_51768_shortcode() {
    $posts = get_posts( array('numberposts' => -1) );
    foreach ( $posts as $post ) {
        $featured = get_the_post_thumbnail( $post->ID, 'thumbnail', null );
        if ( $featured ) echo 'Has Featured Image: ' . $post->post_title . '<br />';
    }
}

[update]

The following outputs the posts that don't have a Featured Image, and if it has one, check if the file is live:

add_shortcode('nofeatures', 'shortcode_wpse_51768');

function shortcode_wpse_51768() 
{
    $args = array(
        'numberposts' => -1,
        'post_type'   => 'post',
        'post_status' => 'publish'
    );
    $posts = get_posts( $args );

    foreach ( $posts as $post ) 
    {
        $featured = has_post_thumbnail( $post->ID );

        if ( !$featured ) 
            echo "<p>Doesn't have Featured Image: <b>" . $post->post_title . "</b></p>";
        else
        {
            $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
            $is_live = check_if_featured_image_is_live( $thumb[0] );
            if ( !$is_live )
                echo '<p>Featured image 404: <b>' . $post->post_title . '</b></p>';
        }
    }
}

// http://stackoverflow.com/a/7953100/1287812
function check_if_featured_image_is_live($url)
{
    $options['http'] = array(
        'method' => "HEAD",
        'ignore_errors' => 1,
        'max_redirects' => 0
    );
    $body = file_get_contents($url, NULL, stream_context_create($options));
    sscanf($http_response_header[0], 'HTTP/%*d.%*d %d', $code);
    return $code === 200;
}
share|improve this answer
    
thnx for your help :) –  Alex Jan 10 '13 at 5:46
1  
From 20% to 80% in 5 minutes ;) ::: The answer is just missing the "not exist anymore" part, I'll take a look. –  brasofilo Jan 10 '13 at 5:50
    
what do you mean? –  Alex Jan 10 '13 at 6:07
    
@Alex, check updated answer. –  brasofilo Jan 10 '13 at 6:37
    
oh!! νow I understand what I meant before, but then when i tried it was OK :) now this i a big update!! thnx again :) –  Alex Jan 10 '13 at 6:47

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.