I have a page which displays tour dates for an artist. I use a custom field (TheDate) to give each entry a numerical value so that they will show up in the proper order (regardless of when they were actually posted). The custom field uses these values: 20110315 (this would be used for a date on March 15, 2011. I want the page to only return dates for today and onward and not to return any dates which have passed. I think I have the basics down, but I'm clearly not doing something right. Here's what I have, but it doesn't return anything. If I take out the filter it works (but returns all dates, even past ones) so I must be doing something wrong with the filter. Any help, advice or direction would be greatly appreciated. Thanks very much.
$todaysdate = date('Ymd');
function filter_where( $where = '' ) {
$where .= " AND ( ($wpdb->postmeta.meta_key = 'TheDate' AND $wpdb->postmeta.meta_value >= $todaysdate) ) ";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$args = array(
'cat' => '4',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => 'TheDate',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );