acf_render_fields()
acf_render_fields
Renders an array of fields. Also loads the field's value.
The $args are:
render_id(string|false): The object the fields are rendered for, which save handlers verify the list against. Defaults to$post_id, or no list if it is empty.prefix(string): The form's base input prefix. Defaultacf.list_name(string|false): The root name of the list input, or false for no list. Default_acf_fields.
Хуки из функции
Возвращает
void. Ничего (null).
Использование
acf_render_fields( $fields, $post_id, $el, $instruction, $args );
- $fields(массив) (обязательный)
- An array of fields.
- $post_id((int|string))
- The post ID to load values from.
- $el
- .
По умолчанию:'div' - $instruction(строка)
- The instruction render position (label|field).
По умолчанию:'label' - $args(массив)
- How the outermost render call outputs the list of rendered top-level field keys, as described above.
По умолчанию:array()
Список изменений
| С версии 5.0.0 | Введена. |
| С версии 5.6.9 | Changed parameter order. |
| С версии 6.8.11 | Added the $args parameter, and outputs the list of rendered top-level field keys. |
Код acf_render_fields() acf render fields ACF 6.8.11
function acf_render_fields( $fields, $post_id = 0, $el = 'div', $instruction = 'label', $args = array() ) {
// Parameter order changed in ACF 5.6.9.
if ( is_array( $post_id ) ) {
list( $fields, $post_id ) = array( $post_id, $fields );
}
/**
* Filters the $fields array before they are rendered.
*
* @date 12/02/2014
* @since 5.0.0
*
* @param array $fields An array of fields.
* @param (int|string) $post_id The post ID to load values from.
*/
$fields = apply_filters( 'acf/pre_render_fields', $fields, $post_id );
// Filter our false results.
$fields = array_filter( $fields );
$args = wp_parse_args(
$args,
array(
'render_id' => $post_id ? (string) $post_id : false,
'prefix' => 'acf',
'list_name' => '_acf_fields',
)
);
// Only the outermost render call lists the keys it rendered.
$rendered = array();
$is_outer = _acf_in_field_render(
$args['render_id'],
function () use ( $fields, $post_id, $el, $instruction, $args, &$rendered ) {
foreach ( $fields as $field ) {
$field = apply_filters( 'acf/pre_render_field', $field, $post_id );
// Load value if not already loaded.
if ( $field['value'] === null ) {
$field['value'] = acf_get_value( $post_id, $field );
}
// Render wrap.
if ( acf_render_field_wrap( $field, $el, $instruction ) ) {
$rendered[] = acf_get_field_root_key( $field, $args['prefix'] );
}
}
}
);
if ( $is_outer ) {
_acf_render_field_list( $rendered, $args['render_id'], $args['list_name'] );
}
/**
* Fires after fields have been rendered.
*
* @date 12/02/2014
* @since 5.0.0
*
* @param array $fields An array of fields.
* @param (int|string) $post_id The post ID to load values from.
*/
do_action( 'acf/render_fields', $fields, $post_id );
}