acf_get_block_meta_values_to_save()
Iterates over blocks in post content and retrieves values that need to be saved to post meta.
Хуков нет.
Возвращает
Массив
. An array containing the field values that need to be saved.
Использование
acf_get_block_meta_values_to_save( $content );
- $content(строка)
- The content saved for the post.
По умолчанию: ''
Список изменений
С версии 6.3 | Введена. |
Код acf_get_block_meta_values_to_save() acf get block meta values to save ACF 6.4.2
function acf_get_block_meta_values_to_save( $content = '' ) { $meta_values = array(); // Bail early if not in a format we expect or if it has no blocks. if ( ! is_string( $content ) || empty( $content ) || ! has_blocks( $content ) ) { return $meta_values; } $blocks = parse_blocks( $content ); // Bail if no blocks to save. if ( ! is_array( $blocks ) || empty( $blocks ) ) { return $meta_values; } foreach ( $blocks as $block ) { // Verify this is an ACF block that should save to meta. if ( ! acf_block_uses_post_meta( $block['attrs'] ) ) { continue; } // We need a block ID to retrieve the values from cache. $block_id = ! empty( $block['attrs']['id'] ) ? $block['attrs']['id'] : false; if ( ! $block_id ) { continue; } // Verify that we have values for this block. $store = acf_get_store( 'block-meta-values' ); if ( ! $store->has( $block_id ) ) { continue; } // Get the values and remove from cache. $block_values = $store->get( $block_id ); $store->remove( $block_id ); $meta_values = array_merge( $meta_values, $block_values ); } return $meta_values; }