acf_get_posts()ACF 5.1.5

acf_get_posts

Similar to the get_posts() function but with extra functionality.

Хуков нет.

Возвращает

Массив.

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

acf_get_posts( $args );
$args(массив)
The query args.
По умолчанию: array()

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

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

Код acf_get_posts() ACF 5.10.2

function acf_get_posts( $args = array() ) {

	// Vars.
	$posts = array();

	// Apply default args.
	$args = wp_parse_args(
		$args,
		array(
			'posts_per_page'         => -1,
			'post_type'              => '',
			'post_status'            => 'any',
			'update_post_meta_cache' => false,
			'update_post_term_cache' => false,
		)
	);

	// Avoid default 'post' post_type by providing all public types.
	if ( ! $args['post_type'] ) {
		$args['post_type'] = acf_get_post_types();
	}

	// Check if specifc post ID's have been provided.
	if ( $args['post__in'] ) {

		// Clean value into an array of IDs.
		$args['post__in'] = array_map( 'intval', acf_array( $args['post__in'] ) );
	}

	// Query posts.
	$posts = get_posts( $args );

	// Remove any potential empty results.
	$posts = array_filter( $posts );

	// Manually order results.
	if ( $posts && $args['post__in'] ) {
		$order = array();
		foreach ( $posts as $i => $post ) {
			$order[ $i ] = array_search( $post->ID, $args['post__in'] );
		}
		array_multisort( $order, $posts );
	}

	// Return posts.
	return $posts;
}