WP_Query::set_found_posts( array $q, string $limits )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Sets up the amount of found posts and the number of pages (if limit clause was used) for the current query.

Parameters

$qarrayrequired
Query variables.
$limitsstringrequired
LIMIT clauses of the query.

Source


if ( ! $q['suppress_filters'] ) {
	/**
	 * Filters the array of retrieved posts after they've been fetched and
	 * internally processed.
	 *
	 * @since 1.5.0
	 *
	 * @param WP_Post[] $posts Array of post objects.
	 * @param WP_Query  $query The WP_Query instance (passed by reference).
	 */
	$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );
}

/*
 * Ensure that any posts added/modified via one of the filters above are
 * of the type WP_Post and are filtered.
 */
if ( $this->posts ) {
	$this->post_count = count( $this->posts );

	/** @var WP_Post[] */
	$this->posts = array_map( 'get_post', $this->posts );

	if ( $q['cache_results'] ) {
		if ( $is_unfiltered_query && $unfiltered_posts === $this->posts ) {
			update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
		} else {
			$post_ids = wp_list_pluck( $this->posts, 'ID' );
			_prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
		}
	}

	/** @var WP_Post */
	$this->post = reset( $this->posts );
} else {
	$this->post_count = 0;
	$this->posts      = array();
}

if ( ! empty( $this->posts ) && $q['update_menu_item_cache'] ) {
	update_menu_item_cache( $this->posts );
}

if ( $q['lazy_load_term_meta'] ) {
	wp_queue_posts_for_term_meta_lazyload( $this->posts );
}

return $this->posts;

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.