元查询比较元键是否在指定范围内

帖子具有与之关联的价格自定义元字段。在前端, 可以通过指定价格范围来搜索帖子, 例如”价格”值大于1且小于10的所有帖子。

管理层决定, 无论出于何种原因, 我们都无法选择使用WooCommerce, 因此我们必须为此使用本地Wordpress。

到目前为止, 这就是我设法完成的get_posts($ args)争论。

$args=array(
            'meta_query' => array(
                array(
                    'key' => 'price', 'value' => 1, 'compare' => '>'
                )
            )
        );

但这只会返回”价格”大于1的帖子。我需要有”价格”字段大于1并且小于10的帖子。

这可能吗?


#1


尝试这样:

$args=array(
                'meta_query' => array(
                    array(
                        'key' => 'price', 'value' => array(1, 10), 'compare' => 'BETWEEN'
                    )
                )
            );

来源:

https://www.srcmini02.com/67409.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40072.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?