Php 在admin中动态拉取灵活的内容子块标题
我正在做一个项目,我正在创建一个在ACF5之上工作的插件。我已经走了很长一段路,但现在我被困在这个问题上: 我有一个灵活的内容字段设置,有多个子布局。我需要根据这些布局的名称向每个布局添加条件逻辑。现在,我通过获取他们的字段ID来执行此操作:Php 在admin中动态拉取灵活的内容子块标题,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我正在做一个项目,我正在创建一个在ACF5之上工作的插件。我已经走了很长一段路,但现在我被困在这个问题上: 我有一个灵活的内容字段设置,有多个子布局。我需要根据这些布局的名称向每个布局添加条件逻辑。现在,我通过获取他们的字段ID来执行此操作: $field_id=$field['id'] $field是我的主数组 然后执行一个简单的php switch语句,设置一个变量,然后在执行条件逻辑时检查: $layout = ''; switch ($field_id) { case "19":
$field_id=$field['id']代码>
$field
是我的主数组
然后执行一个简单的php switch语句,设置一个变量,然后在执行条件逻辑时检查:
$layout = '';
switch ($field_id) {
case "19":
$layout = "html";
break;
case "28":
$layout = "grid";
break;
}
然后我只是检查$layout设置为什么,然后从那里开始。虽然这是可行的,但我不喜欢每次移动开发环境或重新创建布局时都必须更新ID这一事实
有人知道如何更好地做到这一点吗
单个$field的数组转储:
Array
(
[padding_top] => 0
[padding_right] => 0
[padding_bottom] => 0
[padding_left] => 0
[background_style] => default
[section_width] => default
[ID] => 28
[key] => field_5876368ea05b4
[label] => Section Styles
[name] => acf[field_5873e9fdacab1][0][field_5876368ea05b4]
[prefix] => acf[field_5873e9fdacab1][0]
[type] => section_styles
[value] => Array
(
[section_width] => default
[margin_top] =>
[margin_right] =>
[margin_bottom] =>
[margin_left] =>
[padding_top] =>
[padding_right] =>
[padding_bottom] =>
[padding_left] =>
[background_color] =>
[background_image] =>
[background_style] => default
[background_position_1] => top
[background_position_2] => left
)
[menu_order] => 0
[instructions] =>
[required] => 0
[id] => acf-field_5873e9fdacab1-0-field_5876368ea05b4
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => section_styles
[_prepare] => 1
[_valid] => 1
[parent_layout] => 58763683a05b3
[margin_top] =>
[margin_right] =>
[margin_bottom] =>
[margin_left] =>
[background_color] =>
[background_position_1] => top
[background_position_2] => left
)
主生成器对象的数组转储:
Array
(
[layouts] => Array
(
[0] => Array
(
[key] => 5873ea05b5bf2
[name] => html_section
[label] => HTML Section
[display] => block
[sub_fields] => Array
(
[0] => Array
(
[placement] => top
[endpoint] => 0
[ID] => 15
[key] => field_5873f2366de0c
[label] => Content
[name] =>
[prefix] => acf
[type] => tab
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] =>
[_prepare] => 0
[_valid] => 1
[parent_layout] => 5873ea05b5bf2
)
[1] => Array
(
[tabs] => all
[toolbar] => full
[media_upload] => 1
[default_value] =>
[delay] => 0
[ID] => 16
[key] => field_5873f2456de0d
[label] => Content
[name] => content
[prefix] => acf
[type] => wysiwyg
[value] =>
[menu_order] => 1
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => content
[_prepare] => 0
[_valid] => 1
[parent_layout] => 5873ea05b5bf2
)
[2] => Array
(
[multiple] => 0
[allow_null] => 1
[choices] => Array
(
[narrow-width] => Narrow
[default-width] => Default
[full-width] => Full Width
)
[default_value] => Array
(
[0] => default-width
)
[ui] => 0
[ajax] => 0
[placeholder] =>
[return_format] => value
[ID] => 17
[key] => field_5873f2616de0e
[label] => Width
[name] => width
[prefix] => acf
[type] => select
[value] =>
[menu_order] => 2
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => width
[_prepare] => 0
[_valid] => 1
[parent_layout] => 5873ea05b5bf2
)
[3] => Array
(
[placement] => top
[endpoint] => 0
[ID] => 18
[key] => field_5873f28e6de0f
[label] => Apperance
[name] =>
[prefix] => acf
[type] => tab
[value] =>
[menu_order] => 3
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] =>
[_prepare] => 0
[_valid] => 1
[parent_layout] => 5873ea05b5bf2
)
[4] => Array
(
[padding_top] => 0
[padding_right] => 0
[padding_bottom] => 0
[padding_left] => 0
[background_style] => default
[section_width] => default
[ID] => 19
[key] => field_5873f2976de10
[label] => Section Styles
[name] => section_styles
[prefix] => acf
[type] => section_styles
[value] =>
[menu_order] => 4
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] => 100
[class] =>
[id] =>
)
[_name] => section_styles
[_prepare] => 0
[_valid] => 1
[margin_top] => 0
[margin_right] => 0
[margin_bottom] => 0
[margin_left] => 0
[border_top] => 0
[border_right] => 0
[border_bottom] => 0
[border_left] => 0
[border_style] => solid
[border_color] =>
[background_color] =>
[background_position_1] => top
[background_position_2] => left
[parent_layout] => 5873ea05b5bf2
)
)
[min] =>
[max] =>
)
[1] => Array
(
[key] => 58763683a05b3
[name] => grid_section
[label] => Grid Section
[display] => block
[sub_fields] => Array
(
[0] => Array
(
[padding_top] => 0
[padding_right] => 0
[padding_bottom] => 0
[padding_left] => 0
[background_style] => default
[section_width] => default
[ID] => 28
[key] => field_5876368ea05b4
[label] => Section Styles
[name] => section_styles
[prefix] => acf
[type] => section_styles
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => section_styles
[_prepare] => 0
[_valid] => 1
[parent_layout] => 58763683a05b3
[margin_top] =>
[margin_right] =>
[margin_bottom] =>
[margin_left] =>
[background_color] =>
[background_position_1] => top
[background_position_2] => left
)
)
[min] =>
[max] =>
)
)
[min] =>
[max] =>
[button_label] => Add Row
[ID] => 14
[key] => field_5873e9fdacab1
[label] => Main Builder
[name] => main_builder
[prefix] => acf
[type] => flexible_content
[value] => Array
(
[0] => Array
(
[acf_fc_layout] => grid_section
[section_styles] => Array
(
[section_width] => default
[margin_top] =>
[margin_right] =>
[margin_bottom] =>
[margin_left] =>
[padding_top] =>
[padding_right] =>
[padding_bottom] =>
[padding_left] =>
[background_color] =>
[background_image] =>
[background_style] => default
[background_position_1] => top
[background_position_2] => left
[background_position] => top left
[padding] => 0 0 0 0
)
)
[1] => Array
(
[acf_fc_layout] => html_section
[content] =>
[width] => default-width
[section_styles] => Array
(
[section_width] => default
[margin_top] => uk-margin-large-top
[margin_right] => uk-margin-small-right
[margin_bottom] => uk-margin-medium-bottom
[margin_left] =>
[padding_top] =>
[padding_right] =>
[padding_bottom] =>
[padding_left] =>
[background_color] =>
[background_image] =>
[background_style] => default
[background_position_1] => top
[background_position_2] => left
[background_position] => top left
[padding] => 0 0 0 0
)
)
)
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 13
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => main_builder
[_prepare] => 0
[_valid] => 1
)