Custom Field Expiry Date with meta_query

A handy snippet that can be used in conjunction with Advanced Custom Fields as well as the WordPress default custom fields to remove Posts, Pages and Custom Post Types from feeds.

$args = array(
	'post_type' => 'contributor_ad',
	'posts_per_page' => 6,
	'order' => 'DESC',
	'meta_key' => 'expiry_date',
	'meta_query' => array(
        array(
             'key' => 'expiry_date',
             'value' => $today,
             'compare' => '>=',
             'type' => 'DATE',
        )
    )
); 

$contributor_ad = new WP_Query($args);

Note: This does not update the content, or change the Post Status.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.