acf_get_field_group_post()ACF 5.7.10

acf_get_field_group_post

Retrieves the field group's WP_Post object.

Хуков нет.

Возвращает

(Массив|false). The field group's array.

Использование

acf_get_field_group_post( $id );
$id((int|string))
The field group's ID, key or name.

Список изменений

С версии 5.7.10 Введена.

Код acf_get_field_group_post() ACF 5.10.2

function acf_get_field_group_post( $id = 0 ) {

	// Get post if numeric.
	if ( is_numeric( $id ) ) {
		return get_post( $id );

		// Search posts if is string.
	} elseif ( is_string( $id ) ) {

		// Try cache.
		$cache_key = acf_cache_key( "acf_get_field_group_post:key:$id" );
		$post_id   = wp_cache_get( $cache_key, 'acf' );
		if ( $post_id === false ) {

			// Query posts.
			$posts = get_posts(
				array(
					'posts_per_page'         => 1,
					'post_type'              => 'acf-field-group',
					'post_status'            => array( 'publish', 'acf-disabled', 'trash' ),
					'orderby'                => 'menu_order title',
					'order'                  => 'ASC',
					'suppress_filters'       => false,
					'cache_results'          => true,
					'update_post_meta_cache' => false,
					'update_post_term_cache' => false,
					'acf_group_key'          => $id,
				)
			);

			// Update $post_id with a non false value.
			$post_id = $posts ? $posts[0]->ID : 0;

			// Update cache.
			wp_cache_set( $cache_key, $post_id, 'acf' );
		}

		// Check $post_id and return the post when possible.
		if ( $post_id ) {
			return get_post( $post_id );
		}
	}

	// Return false by default.
	return false;
}