acf_maybe_get_sub_field()
This function will attempt to find a sub field
Хуков нет.
Возвращает
$post_id. (int)
Использование
acf_maybe_get_sub_field( $selectors, $post_id, $strict );
- $selectors(обязательный)
- .
- $post_id
- .
По умолчанию: false - $strict
- .
По умолчанию: true
Список изменений
| С версии 5.4.0 | Введена. |
Код acf_maybe_get_sub_field() acf maybe get sub field ACF 6.4.2
function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true ) {
// bail early if not enough selectors
if ( ! is_array( $selectors ) || count( $selectors ) < 3 ) {
return false;
}
// vars
$offset = acf_get_setting( 'row_index_offset' );
$selector = acf_extract_var( $selectors, 0 );
$selectors = array_values( $selectors ); // reset keys
// attempt get field
$field = acf_maybe_get_field( $selector, $post_id, $strict );
// bail early if no field
if ( ! $field ) {
return false;
}
// loop
for ( $j = 0; $j < count( $selectors ); $j += 2 ) {
// vars
$sub_i = $selectors[ $j ];
$sub_s = $selectors[ $j + 1 ];
$field_name = $field['name'];
// find sub field
$field = acf_get_sub_field( $sub_s, $field );
// bail early if no sub field
if ( ! $field ) {
return false;
}
// add to name
$field['name'] = $field_name . '_' . ( $sub_i - $offset ) . '_' . $field['name'];
}
// return
return $field;
}