php WordPress高级自定义字段按钮组代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WordPress高级自定义字段按钮组代码相关的知识,希望对你有一定的参考价值。

[
    {
        "key": "group_5d51aa5ca0e01",
        "title": "Base Fields to Duplicate and Move",
        "fields": [
            {
                "key": "field_5d51aaef15c2a",
                "label": "Button",
                "name": "button",
                "type": "group",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "link-group",
                    "id": ""
                },
                "layout": "block",
                "sub_fields": [
                    {
                        "key": "field_5d51ab1915c2b",
                        "label": "Text",
                        "name": "content",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "link-text",
                            "id": ""
                        },
                        "default_value": "Learn More",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": ""
                    },
                    {
                        "key": "field_5d51ab4d15c2c",
                        "label": "Link Type",
                        "name": "type",
                        "type": "true_false",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "link-type",
                            "id": ""
                        },
                        "message": "",
                        "default_value": 1,
                        "ui": 1,
                        "ui_on_text": "Local",
                        "ui_off_text": "External"
                    },
                    {
                        "key": "field_5d51ab7a15c2d",
                        "label": "Local Page",
                        "name": "local_page",
                        "type": "page_link",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": [
                            [
                                {
                                    "field": "field_5d51ab4d15c2c",
                                    "operator": "==",
                                    "value": "1"
                                }
                            ]
                        ],
                        "wrapper": {
                            "width": "",
                            "class": "link-picker",
                            "id": ""
                        },
                        "post_type": "",
                        "taxonomy": "",
                        "allow_null": 0,
                        "allow_archives": 1,
                        "multiple": 0
                    },
                    {
                        "key": "field_5d51ab9715c2e",
                        "label": "External URL",
                        "name": "external_url",
                        "type": "url",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": [
                            [
                                {
                                    "field": "field_5d51ab4d15c2c",
                                    "operator": "!=",
                                    "value": "1"
                                }
                            ]
                        ],
                        "wrapper": {
                            "width": "",
                            "class": "link-picker",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": ""
                    }
                ]
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "post"
                },
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "page"
                }
            ]
        ],
        "menu_order": 0,
        "position": "normal",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": "",
        "active": true,
        "description": ""
    }
]
<?php

function update_button_href($value, $post_id, $field) {
  if($field['sub_fields'][0]['type'] == 'text' && $field['sub_fields'][1]['type'] == 'true_false' && $field['sub_fields'][2]['type'] == 'page_link') {
    $value['href'] = $value['type'] ? $value['local_page'] : ($value['external_url'] ? $value['external_url'] : '');
  }
  return $value;
}

add_filter('acf/format_value/type=group', 'update_button_href', 1000, 3);

以上是关于php WordPress高级自定义字段按钮组代码的主要内容,如果未能解决你的问题,请参考以下文章

如何检查 Wordpress 高级自定义字段插件中的字段组?

以编程方式更新转发器字段中特定组字段的值 - 高级自定义字段 (ACF) - Wordpress

高级自定义字段 wordpress 图像大小

WordPress 和高级自定义字段管理,仪表板中的自定义列

php PHP - Wordpress - 搜索 - wordpress自定义搜索功能,包含ACF /高级自定义字段和分类法以及拆分表达式

php PHP - Wordpress - 搜索 - wordpress自定义搜索功能,包含ACF /高级自定义字段和分类法以及拆分表达式