我正在制作一个搜索表单,在两个元框值内搜索帖子,并在它们之间显示结果。
我有这套
$prefix = \'ghes_\'; // start with an underscore to hide fields from custom fields list
add_filter( \'ghes_meta_boxes\', \'ghes_sample_metaboxes\' );
function ghes_sample_metaboxes( $meta_boxes ) {
    global $prefix;
    $meta_boxes[] = array(
        \'id\' => \'event_meta\',
        \'title\' => \'Event Metabox\',
        \'pages\' => array(\'event\'), // post type
        \'context\' => \'normal\',
        \'priority\' => \'high\',
        \'show_names\' => true, // Show field names on the left
        \'fields\' => array(
        array(
                \'name\' => \'Event Start Date\',
                \'desc\' => \'field description (optional)\',
                \'id\' => $prefix . \'event_start_timestamp\',
                \'type\' => \'text_date_timestamp\'
            ),                  
            array(
                \'name\' => \'Event End Date\',
                \'desc\' => \'field description (optional)\',
                \'id\' => $prefix . \'event_end_timestamp\',
                \'type\' => \'text_date_timestamp\'
            )                   
如果我想在“事件开始日期”和“事件结束日期”之间搜索帖子,查询会是什么样子。
谢谢
 
                SO网友:Ijaas
                您需要使用meta_query 类似这样的变量:
$start = time(); //Now
$end= strtotime(\'+1 month\'); //1 month ahead
query_posts(
    \'post_type\' => \'event\',
    \'post_status\' => \'publish\',
    \'posts_per_page\' => \'10\',
    \'meta_query\' => array(
        array(\'key\' => $prefix.\'event_start_timestamp\', \'value\' => $start, \'compare\' => \'>=\', \'type\' => \'NUMERIC\'),
        array(\'key\' => $prefix.\'event_end_timestamp\', \'value\' => $end, \'compare\' => \'<=\', \'type\' => \'NUMERIC\')
    )
);