wp-includes/class-wp-query.php:1865Retrieves an array of posts based on query variables.
WP_Post[]|int[]40 hooks fire while WP_Query::get_posts() runs, in this order:
Fires after the query variable object is created, but before the actual query is run.
Filters whether an attachment query should include filenames or not.
Filters the search SQL that is used in the WHERE clause of WP_Query.
Filters the ORDER BY used when ordering search results.
Filters the WHERE clause of the query.
Filters the JOIN clause of the query.
Filters the JOIN clause of the comments feed query before sending.
Filters the WHERE clause of the comments feed query before sending.
Filters the GROUP BY clause of the comments feed query before sending.
Filters the ORDER BY clause of the comments feed query before sending.
Filters the LIMIT clause of the comments feed query before sending.
Filters the WHERE clause of the query.
Filters the GROUP BY clause of the query.
Filters the JOIN clause of the query.
Filters the ORDER BY clause of the query.
Filters the DISTINCT clause of the query.
Filters the LIMIT clause of the query.
Filters the SELECT clause of the query.
Filters all query clauses at once, for convenience.
Fires to announce the query's current selection parameters.
Filters the WHERE clause of the query.
Filters the GROUP BY clause of the query.
Filters the JOIN clause of the query.
Filters the ORDER BY clause of the query.
Filters the DISTINCT clause of the query.
Filters the SELECT clause of the query.
Filters the LIMIT clause of the query.
Filters all query clauses at once, for convenience.
Filters the completed SQL query before sending.
Filters the posts array before the query takes place.
Filters whether to split the query.
Filters the Post IDs SQL request before sending.
Filters the raw post results array, prior to status checks.
Filters the JOIN clause of the comments feed query before sending.
Filters the WHERE clause of the comments feed query before sending.
Filters the GROUP BY clause of the comments feed query before sending.
Filters the ORDER BY clause of the comments feed query before sending.
Filters the LIMIT clause of the comments feed query before sending.
Filters the single post for preview mode.
Filters the array of retrieved posts after they've been fetched and internally processed.
public function get_posts() { global $wpdb; $this->parse_query(); /** * Fires after the query variable object is created, but before the actual query is run. * * Note: If using conditional tags, use the method versions within the passed instance * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions * like is_main_query() test against the global $wp_query instance, not the passed one. * * @since 2.0.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */ do_action_ref_array( 'pre_get_posts', array( &$this ) ); // Shorthand. $q = &$this->query_vars; // Fill again in case 'pre_get_posts' unset some vars. $q = $this->fill_query_vars( $q ); /** * Filters whether an attachment query should include filenames or not. * * @since 6.0.3 * * @param bool $allow_query_attachment_by_filename Whether or not to include filenames. */ $this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false ); remove_all_filters( 'wp_allow_query_attachment_by_filename' ); // Parse meta query. $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars( $q ); // Set a flag if a 'pre_get_posts' hook changed the query vars. $hash = md5( serialize( $this->query_vars ) ); if ( $hash != $this->query_vars_hash ) { $this->query_vars_changed = true; $this->query_vars_hash = $hash; } unset( $hash ); // First let's clear some variables. $distinct = ''; $whichauthor = ''; $whichmimetype = ''; $where = ''; $limits = ''; $join = ''; $search = ''; $groupby = ''; $post_status_join = false; $page = 1; if ( isset( $q['caller_get_posts'] ) ) { _deprecated_argument( 'WP_Query', '3.1.0', sprintf( /* translators: 1: caller_get_posts, 2: ignore_sticky_posts */ __( '%1$s is deprecated. Use %2$s instead.' ), '<code>caller_get_posts</code>', '<code>ignore_sticky_posts</code>' ) ); if ( ! isset( $q['ignore_sticky_posts'] ) ) { $q['ignore_sticky_posts'] = $q['caller_get_posts']; } } if ( ! isset( $q['ignore_sticky_posts'] ) ) { $q['ignore_sticky_posts'] = false; } if ( ! isset( $q['suppress_filters'] ) ) {Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/class-wp-query.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.