Custom Field Date Problem

I agree with Denis, I don’t like using custom fields for this kind of stuff, but I’m not aware of any other way yet…

What you what can be done by altering the SQL query for the loop, something like this:

add_filter('posts_join', 'my_post_filter_join');
function my_post_filter_join($join) {
  global $wpdb;
  if(is_home() || is_category() || is_search())
    $join .= " LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
  return $join;
}

add_filter('posts_where', 'my_post_filter_where');
function my_post_filter_where($where) {
  global $wpdb;

  // current date in unix format
  $current_time = current_time("timestamp");

  // exclude any posts older than your expiry date set in the custom field
  if(is_home()|| is_category() || is_search())
    $where .= " AND ($wpdb->postmeta.meta_key = 'expiry_date' AND $wpdb->postmeta.meta_value > '{$current_time}')";
  return $where;
}

I used unix timestamps here instead of a formatted date string, you should do that too, it’s easier to handle. For the admin interface you can use a datepicker and convert the date to a timestamp when the post is saved…