Yep. You can add a meta_query parameter to methods that query posts, such as WP_Query. This one below gets a custom post type between two dates (which are custom fields created by ‘advanced custom fields’ plugin) and sorts on one of these dates:
$args = array(
'post_type' => 'event',
'posts_per_page' => '-1',
'post_status' => array( 'private','publish' ),
'meta_key' =>'start_date',
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'end_date',
'value' => array(strtotime('20130101'),strtotime('20140101')),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'start_date',
'value' => array(strtotime('20130101'),strtotime('20140101')),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
)
)
);
$search = new WP_Query($args);
if ( $search->have_posts() ):
setlocale(LC_ALL, 'nl_NL.UTF-8');
while ( $search->have_posts() ) : $search->the_post();
$start_date = get_post_meta(get_the_ID(), 'start_date', true);
$end_date = get_post_meta(get_the_ID(), 'end_date', true);
$start = strftime( '%A %e %B %Y', strtotime( $start_date ) );
$end = strftime( '%A %e %B %Y', strtotime( $end_date ) );
echo "$start ($start_date) - $end ($end_date) <br />";
endwhile;
endif;
See here also: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters