使用WP_Meta_Query过滤数据

时间:2018-10-25 10:08:48

标签: wordpress meta-query

我想按餐厅的座位数搜索餐厅。我将从下拉菜单中选择一个数字,并且我必须显示最小容纳人数和最大容纳人数之间的餐厅。我尝试下面的代码。但是它始终没有显示结果。

$_seating_capacity  = $_GET['seating_capacity'] != '' ? $_GET['seating_capacity'] : '';
$_standing_capacity = $_GET['standing_capacity'] != '' ? $_GET['standing_capacity'] : '';
$_neighborhood      = $_GET['neighborhood'] != '' ? $_GET['neighborhood'] : '';
// Start the Query
$v_args = array(
    'post_type'  => 'Dinings', // your CPT
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'relation' => 'OR',
            array(
                'relation' => 'AND',
                array( 'key'     => 'min_capacity_sit',
                       'value'   => $_seating_capacity,
                       'compare' => '=>',
                       'type'    => 'NUMERIC',
                ),
                //AND Conditation
                array( 'key'     => 'max_capacity_sit',
                       'value'   => $_seating_capacity,
                       'compare' => '<=',
                       'type'    => 'NUMERIC',
                )
            ),

            //OR Conditation
            array( 'key'     => 'max_capacity_stand',
                   'value'   => $_standing_capacity,
                   'compare' => '<=',
                   'type'    => 'NUMERIC',
            )
        ),
        //AND Conditation
        array( 'key' => 'neighborhood', 'value' => $_neighborhood, 'compare' => 'Like', ),
    )
);

1 个答案:

答案 0 :(得分:0)

您使用=>进行比较时出错,但语法为>=

这也是一个查询。如果还有其他问题,我建议您注释掉每个步骤。一次打开一个步骤,一次调试也一次。

documentation of WP_Query