WordPress自定义字段-表格字段-按表格行值查询帖子
·
问题:WordPress自定义字段-表格字段-按表格行值查询帖子
我想在 wordpress 中创建一个带有自定义字段的表。它看起来像这样:
+---------------------------------------------+
| company | | | |
| | field1 | field2 | Field3 |
| | | | |
+----+-----------+----------+----------+------+
| 56 | 5 | 55 | 58 |
+----+-----------+----------+-- -------+------+
| 888 | 6 | 88 | 55 |
+----+-----------+----------+-- -------+------+
| 558 | 88 | 2 | 150 |
+----+-----------+----------+----------+------+
我需要创建一个过滤器来加载帖子列表,其中:
"company" == 888
"field1" <= 100 &&
"field2" >= 20 &&
"field3" >= 40
例如,在这种情况下,具有此值的帖子(如 table up)将在此列表中提及。表格中可以有无限的数量或行。
如果只有一个字段具有一个值,我会做这样的事情:
$args = array(
'numberposts' => -1,
'post_type' => 'company',
'meta_query' => array(
array(
'key' => $key_name,
'value' => 0,
'compare' => '>'
)
)
);
我找不到以这种方式查询表中数据的方法?在那儿?非常感谢您的帮助。
编辑:
她是我创造的服装领域。我把它当作中继器。 **一件重要的事情:**我需要在同一行(行)上找到所有条件都满足的公司。
[
{
"key": "group_5dcbf625e861c",
"title": "Product search params (copy)",
"fields": [
{
"key": "field_5dcbf62629ce7",
"label": "product search by param active",
"name": "product_search_by_param_active",
"type": "true_false",
"instructions": "Please choose true to activate this option",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "If not checked, search engine won't show this section on website",
"default_value": 0,
"ui": 0,
"ui_on_text": "",
"ui_off_text": ""
},
{
"key": "field_5dcbf6262a106",
"label": "product params values",
"name": "product_params_values",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_5dcbf62629ce7",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "",
"sub_fields": [
{
"key": "field_5dcbf626543aa",
"label": "param value 1",
"name": "param_value_1",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_5dcbf6265478f",
"label": "param value 2",
"name": "param_value_2",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_5dcbf62654c14",
"label": "param value 3",
"name": "param_value_3",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_5dcbf62654fc1",
"label": "param value 4",
"name": "param_value_4",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_5dcbf62655398",
"label": "param value 5",
"name": "param_value_5",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
}
]
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "product"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]
编辑2:
还有另一种方法。创建表字段。那是领域:
{
"key": "field_5dcdf5a673fa7",
"label": "product search by param settings",
"name": "product_search_by_param_settings",
"type": "table",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"use_header": 0,
"use_caption": 2
}
这就是它的保存方式:
a:5:{s:5:"acftf";a:1:{s:1:"v";s:5:"1.3.9";}s:1:"p";a:2:{s:1:"o";a:1:{s:2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1:"c";s:4:"hkhk";}}}}
解答
元查询可以采用一系列条件。在您的情况下,您可以尝试:
$args = array(
'numberposts' => -1,
'post_type' => 'company',
'meta_query' => array(
'relation' => 'AND', // AND is default, you can use OR as well
array(
'key' => 'company',
'value' => 888,
'compare' => '='
),
array(
'key' => 'field1',
'value' => 100,
'compare' => '<=',
'type' => 'NUMERIC' // You can add a type here as well
), array(
'key' => 'field2',
'value' => 20,
'compare' => '>=',
'type' => 'NUMERIC'
), array(
'key' => 'field3',
'value' => 40,
'compare' => '>=',
'type' => 'NUMERIC'
)
)
);
这是帮助深入了解 meta_query 的链接:https://rudrastyh.com/wordpress/meta_query.html
此外,这里有一个元查询生成器来帮助处理这个过程:https://generatewp.com/wp_meta_query/
更多推荐
所有评论(0)