Forums

[resolved] Random posts only if thumbnail (3 posts)

  1. zeaks
    Member
    Posted 11 months ago #

    I'm using this code to display random images in my footer on post pages.
    http://pastebin.com/Q9eKxfCG

    It works, but not all of my posts have a thumbnail image. How can I make it only show posts that have a thumbnail?

    Thanks for any help.

  2. alchymyth
    The Sweeper
    Posted 11 months ago #

    this seems to do the trick:

    $args = array( 'numberposts' => 6, 'orderby' => 'rand', 'meta_key' => '_thumbnail_id'
     );

    ref: http://wordpress.org/support/topic/display-the-post-only-if-thumbnail-is-set-up?replies=17

  3. zeaks
    Member
    Posted 11 months ago #

    Works great, thanks alot alchymyth

Reply

You must log in to post.

About this Topic