Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

get_potd

// WP_Query arguments
$args = array(
	'post_type'              => array( 'attachment' ),
	'post_status'            => array( 'any' ),
	'nopaging'               => true,
	'posts_per_page'         => '1',
	'meta_query'             => array(
		array(
			'key'     => 'picture_of_day',
			'value'   => '1',
			'compare' => '=',
		),
	),
);

// The Query
$attachement = new WP_Query( $args );

// The Loop
if ( $attachement->have_posts() ) {
	while ( $attachement->have_posts() ) {
		$attachement->the_post();
		// do something
	}
} else {
	// no posts found
}

// Restore original Post Data
wp_reset_postdata();