gpt4 book ai didi

wordpress - wp_query 和 meta_query 用于转发器字段值

转载 作者:行者123 更新时间:2023-12-03 17:20:16 24 4
gpt4 key购买 nike

我有一个带有自定义字段的文字新闻网站。
我需要将转发器字段作为表进行查询。它看起来像这样:

        | param_1 | param_2 | param_2  | param_4
| 20 | 20 | 20 | 20
| 555 | 680 | 56 | 0
| 5555 | 45 | 56 | 1
| 69 | 0 | 45 | 0

只有当它与同一行中的查询匹配时,我才需要查询此转发器以获取结果

我的元查询看起来像这样:
[post_type] => product
[posts_per_page] => -1
[orderby] => title
[order] => ASC
[meta_query] => Array (
[relation] => AND
[0] => Array (
[key] => BBBproduct_params_values_AAA_param_value_0
[value] => 25
[compare] => <=
[type] => NUMERIC
)
[1] => Array (
[key] => BBBproduct_params_values_AAA_param_value_1
[value] => 56
[compare] => >=
[type] => NUMERIC
)
[2] => Array (
[key] => BBBproduct_params_values_AAA_param_value_2
[value] => 56
[compare] => >=
[type] => NUMERIC
)
[3] => Array (
[key] => BBBproduct_params_values_AAA_param_value_3
[value] => 0
[compare] => =
[type] => NUMERIC
)
)

她是通过以下代码创建的:
if( $product_search_by_param_active ){
function my_posts_where( $where ){


$where = str_replace("AAA_param_value_", "%_param_value_", $where);
$where = str_replace("meta_key = 'BBBproduct_params_values_", "meta_key LIKE 'product_params_values_", $where);


return $where;
}
add_filter('posts_where', 'my_posts_where');


$range_angine_settings = get_field('param_search_range_settings');
$search_args['meta_query'] = array();
$search_args['meta_query'] ['relation'] = 'AND';


foreach( $range_angine_settings as $rangekey => $search_range ){
${'range-'.$rangekey} = $_GET['range-'.$rangekey]? $_GET['range-'.$rangekey] : '0';
if ( $_GET['range-'.$rangekey] ) $has_range_query = true;
//$pre_prama_value = 'product_params_values_'.strval($rangekey).'_param_value_AAA';

if( isset($_GET['range-'.$rangekey])){
$search_args['meta_query'][] = array(
"key" => 'BBBproduct_params_values_AAA_param_value_'.strval($rangekey),
"value" => $search_range['search_metric_ranges'][${'range-'.$rangekey}]['range_value'],
"compare" => $search_range['product_search_logic'],
'type' => 'NUMERIC'
);
}
}
}

问题是,即使查询匹配不在同一行上,我也会因为 '%' 而得到结果。

在上面的例子中,它不打算得到任何结果,但由于在不同的行上满足每个条件,我确实得到了结果。

有没有办法创建这个查询之王以按行号给出结果?

最佳答案

对我来说,我更喜欢将 CMB2 用于自定义字段
https://github.com/CMB2/CMB2

关于wordpress - wp_query 和 meta_query 用于转发器字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59480994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com