是的。您可以将meta\\u查询参数添加到查询帖子的方法中,例如WP\\u query。下面这篇文章获取两个日期之间的自定义帖子类型(这是由“高级自定义字段”插件创建的自定义字段),并在其中一个日期排序:
$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;
另请参见此处:
http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters