【问题标题】:searching by meta values showing inappropriate result按显示不适当结果的元值搜索
【发布时间】:2014-03-07 06:24:00
【问题描述】:

我正在按元值进行自定义搜索并使用它:

print_r($_REQUEST);
$args = array(
    'post_type' => 'property_post',
    'posts_per_page' => 10,
    'order' => 'ASC',
    'meta_query' => array(
                     'relation' => 'OR',
                     array(
                      'key' => 'custom_textarea',
                      'value' => 'me',  // if I use static keyword it works
                      'compare' => 'LIKE'
                      ),
                      array(
                      'key' => 'custom_price',
                      'value' => array( $_REQUEST['custom_price'], $_REQUEST['custom_price1'] ),
                      'type' => 'numeric',
                      'compare' => 'BETWEEN'
                      ),
                      array(
                      'key' => 'custom_beds',
                      'value' => $_REQUEST['custom_beds'],
                      'compare' => '='
                      ),
                      array(
                      'key' => 'custom_bath',
                      'value' => $_REQUEST['custom_bath'],
                      'compare' => '='
                      ),
                      array(
                      'key' => 'custom_garage',
                      'value' => $_REQUEST['custom_garage'],
                      'compare' => '='
                      )
                      )

);

如果我对元值使用一些静态关键字,那么它可以工作,但使用 $_REQUEST 它没有。 我通过print_r($_REQUEST)检查了$_REQUEST

Array ( [custom_textarea] => aa[custom_price] => 1000 [custom_price1] => 4000[custom_beds] => 2[custom_garage] => 1)

那我该怎么做才能让它好起来。

提前致谢…………

【问题讨论】:

    标签: php wordpress search custom-post-type


    【解决方案1】:

    将 $_REQUEST 值存储到一些变量中并在查询中使用它

               $a=$_REQUEST['custom_price'];
    

            'value' => $a,
    

    【讨论】:

    • 我在我的程序中使用过这样的方法。因为你得到了 $_REQUEST 值。它应该可以工作
    猜你喜欢
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2016-05-07
    • 2021-12-31
    • 2012-08-05
    相关资源
    最近更新 更多