Forums

[resolved] Random Posts with Featured Image (5 posts)

  1. Martin Black
    Member
    Posted 8 months ago #

    Is there a way to use query_posts to collect only posts which have had a featured image set? (i.e. the "set featured image" has been done through the admin panel when posting the items).

    I am in the process of creating a random posts showing only thumbnails so this would be quite handy to be able to exclude post which don't have a featured image.

    Thanks.

  2. Martin Black
    Member
    Posted 8 months ago #

    I believe that this requires a join between wp_posts table and the wp_postmeta table wherein lies _wp_attached_file though I'm not sure if this correct. Or how to do it. Any help would be appreciated.

    Thanks

  3. TheDoc
    Member
    Posted 8 months ago #

    I have a feeling you could do something like this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
        if(has_post_thumbnail()) {
            the_content();
    	the_post_thumbnail();
        }
    endwhile; ?>
  4. alchymyth
    The Sweeper
    Posted 8 months ago #

  5. Martin Black
    Member
    Posted 8 months ago #

    Excellent. Thanks!

Reply

You must log in to post.

About this Topic