我正在构建一个houses类,我想用查询过滤这些房屋。但没有得到任何结果:
示例房屋:
最低价格:10
最高价格(不需要字段):空
我设置了价格过滤器Min price 6 - Max price 15我使用此查询获取结果,但它不起作用。
new \\WP_Query(
[
\'post_type\' => \'properties\',
\'meta_query\' => [
\'relation\' => \'AND\',
\'min_price\' => [
\'relation\' => \'AND\',
[
\'key\' => \'min_price\',
\'value\' => 6,
\'compare\' => \'>=\',
\'type\' => \'NUMERIC\'
],
],
\'max_price\' => [
\'relation\' => \'AND\',
[
\'key\' => \'max_price\',
\'value\' => 11,
\'compare\' => \'<=\',
\'type\' => \'NUMERIC\'
],
[
\'key\' => \'max_price\',
\'value\' => \'\',
\'compare\' => \'!=\',
],
],
],
]
);
我还想知道如何使它与所需的最小值和可选的最大值一起工作。我对卧室、浴室等也有同样的问题。
提前感谢!
这是我用于测试目的的简单示例,但它不起作用。最小价格不是问题,但当我添加最大价格时,它不起作用。
\'relation\' => \'AND\',
[
\'key\' => \'min_price\',
\'value\' => 6,
\'type\' => \'NUMERIC\',
\'compare\' => \'>=\'
],
[
\'key\' => \'max_price\',
\'value\' => 13,
\'type\' => \'NUMERIC\',
\'compare\' => \'<=\'
]
SQL QUERY
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) WHERE 1=1 AND (
(
( wp_postmeta.meta_key = \'min_price\' AND CAST(wp_postmeta.meta_value AS SIGNED) >= \'6\' )
AND
( mt1.meta_key = \'max_price\' AND CAST(mt1.meta_value AS SIGNED) <= \'13\' )
)
) AND wp_posts.post_type = \'properties\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'acf-disabled\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 999
Update CAUSES
\'relation\' => \'OR\',
[
\'key\' => \'min_price\',
\'value\' => 6,
\'type\' => \'NUMERIC\',
\'compare\' => \'>=\'
],
[
\'key\' => \'max_price\',
\'type\' => \'NUMERIC\',
\'value\' => [6, 13],
\'compare\' => \'BETWEEN\'
]