Support » Plugins and Hacks » Hacks » Get random post which has featured image

Viewing 2 replies - 1 through 2 (of 2 total)
  • This should do it:

    <?php 
    
    	$args = array(
    		'post_type' => 'post',
    		'orderby' => 'rand',
    		'posts_per_page' => 1,
    		'meta_key' => '_thumbnail_id'
    	);
    	$query = new WP_Query($args);
    
    	while ( $query->have_posts() ) { $query->the_post();
    		//do stuff here (the_title() or the_content(), etc)
    	} wp_reset_postdata(); 
    
    ?>

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get random post which has featured image’ is closed to new replies.