【发布时间】:2019-03-03 23:00:55
【问题描述】:
我在我的网站上使用 ACF 插件,并且需要一种情况,即仅当其他字段不为空时才需要某个字段。在这种特殊情况下,不需要“标题”字段。但是,当以下字段之一不为空时,它必须是必需的:交易或折扣、描述、常规价格、折扣价/交易价格和有效期至。我需要这种情况,因为要么所有字段都需要为空,要么所有字段都需要填写。
这是我目前创建的 json 代码:
[
{
"key": "group_deal1",
"title": "Deal 1 test 2 (displayed on homepage)",
"fields": [
{
"key": "field_deal1title",
"label": "Title",
"name": "deal_title_one_test1",
"type": "text",
"instructions": "(max. 100 characters)",
"required": [
[
{
"field": "field_deal1dealdiscount",
"operator": "!=empty"
}
],
[
{
"field": "field_deal1description",
"operator": "!=empty"
}
],
[
{
"field": "field_deal1regularprice",
"operator": "!=empty"
}
],
[
{
"field": "field_deal1discountedprice",
"operator": "!=empty"
}
],
[
{
"field": "field_deal1validdate",
"operator": "!=empty"
}
]
],
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "deals-title",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": 100
},
{
"key": "field_deal1dealdiscount",
"label": "Deal or Discount",
"name": "discount_deal_or_special_one",
"type": "radio",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"Discount": "Discount",
"Deal": "Deal"
},
"allow_null": 1,
"other_choice": 0,
"default_value": "",
"layout": "vertical",
"return_format": "value",
"save_other_choice": 0
},
{
"key": "field_deal1description",
"label": "Description",
"name": "deal_description_one",
"type": "textarea",
"instructions": "(max. 600 characters)",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "deals-description",
"id": ""
},
"default_value": "",
"placeholder": "",
"maxlength": 600,
"rows": "",
"new_lines": ""
},
{
"key": "field_deal1regularprice",
"label": "Regular price",
"name": "regular_price_one",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "deals-regular-price",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "$",
"append": "",
"min": "",
"max": "",
"step": ""
},
{
"key": "field_deal1discountedprice",
"label": "Discounted price \/ deal price",
"name": "discounted_price_one",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "deals-discounted-price",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "$",
"append": "",
"min": "",
"max": "",
"step": ""
},
{
"key": "field_deal1validdate",
"label": "Valid until",
"name": "valid_until_one",
"type": "date_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "m\/d\/Y",
"return_format": "m\/d\/Y",
"first_day": 1
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "post"
},
{
"param": "post_format",
"operator": "==",
"value": "aside"
}
],
[
{
"param": "post_format",
"operator": "==",
"value": "status"
}
]
],
"menu_order": 1,
"position": "acf_after_title",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]
它不起作用..它给了我一个结果,其中标题字段始终是必需的。
希望有人可以提供帮助。提前谢谢!
附言。我知道如何使用条件逻辑隐藏字段,但这不会清空字段,因此仍然可以在网站上看到。因此,另一种解决方案是在 Title 为空时清空字段。
【问题讨论】:
标签: json wordpress advanced-custom-fields