WP_Query::get_posts(): WP_Post[]|int[]
- Since
- 1.5.0
- Source
wp-includes/class-wp-query.php:1894
Description
There are a few filters and actions that can be used to modify the post database query.
Compatibility
- WordPress
- since 1.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
WP_Post[]|int[]- Array of post objects or post IDs.
Performance profile
How much work a call to WP_Query::get_posts() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 463–563
- Plugin surface
- 35 hooks
- Called by
- 1
Reaches the database via get_post().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 3324.
Third-party callbacks on 'pre_get_posts', 'wp_allow_query_attachment_by_filename', 'posts_search' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action_ref_array()called directly - optionoption read or write
get_option()called directly - querycontent query
get_post()called directly - cacheobject cache
wp_cache_get_last_changed()called directly - serializeserialisation
serialize()called directly
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 32 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Query::get_posts() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 463–495 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 468–500 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 470–500 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 475–505 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 479–511 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 484–516 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), reset(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 486–516 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), reset(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 491–521 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), reset(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $unfiltered_posts === false | 496–528 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), update_post_caches(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 496–531 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), wp_list_pluck(), _prime_post_caches(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $unfiltered_posts === false | 501–533 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), update_post_caches(), reset(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 501–536 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), wp_queue_posts_for_term_meta_lazyload() |
20 further outcomes, up to 563 instructions
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $unfiltered_posts === false | 503–533 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), update_post_caches(), reset(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 503–536 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 504–517 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $unfiltered_posts === false | 508–538 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), update_post_caches(), reset(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 508–541 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 509–522 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 511–522 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 516–527 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 520–533 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 525–538 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), reset(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 527–538 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), reset(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 532–543 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), reset(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i && $unfiltered_posts === false | 537–550 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), update_post_caches(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 537–553 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), wp_list_pluck(), _prime_post_caches(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i && $unfiltered_posts === false | 542–555 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), update_post_caches(), reset(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 542–558 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i && $unfiltered_posts === false | 544–555 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), update_post_caches(), reset(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 544–558 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), update_menu_item_cache() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i && $unfiltered_posts === false | 549–560 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), update_post_caches(), reset(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $page && is_array($sticky_posts) && !$i | 549–563 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), addslashes_gpc(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), get_option(), post__in(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), update_menu_item_cache(), wp_queue_posts_for_term_meta_lazyload() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 3320 | 462–562 | 351 | 4 fewer instructions than PHP 8.5 |
| 8.5 | 3324 | 463–563 | 351 | |
| 8.4 | 3324 | 463–563 | 351 | 132 fewer instructions than PHP 8.3 |
| 8.3 | 3456 | 474–574 | 351 | |
| 8.2 | 3456 | 474–574 | 351 | 1 more instruction than PHP 8.1 |
| 8.1 | 3455 | 474–574 | 351 | 25 fewer instructions than PHP 7.4 |
| 7.4 | 3480 | 474–574 | 351 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 40
40 hooks fire while WP_Query::get_posts() runs, in this order:
- do_action( pre_get_posts )actionline 1910 (+16 into the body)
Fires after the query variable object is created, but before the actual query is run.
- apply_filters( wp_allow_query_attachment_by_filename )filterline 1925 (+31 into the body)
Filters whether an attachment query should include filenames or not.
- apply_filters( posts_search )filterline 2291 (+397 into the body)
Filters the search SQL that is used in the WHERE clause of WP_Query.
- apply_filters( posts_search_orderby )filterline 2566 (+672 into the body)
Filters the ORDER BY used when ordering search results.
- apply_filters( posts_where )filterline 2788 (+894 into the body)
Filters the WHERE clause of the query.
- apply_filters( posts_join )filterline 2798 (+904 into the body)
Filters the JOIN clause of the query.
- apply_filters( comment_feed_join )filterline 2839 (+945 into the body)
Filters the JOIN clause of the comments feed query before sending.
- apply_filters( comment_feed_where )filterline 2849 (+955 into the body)
Filters the WHERE clause of the comments feed query before sending.
- apply_filters( comment_feed_groupby )filterline 2859 (+965 into the body)
Filters the GROUP BY clause of the comments feed query before sending.
- apply_filters( comment_feed_orderby )filterline 2869 (+975 into the body)
Filters the ORDER BY clause of the comments feed query before sending.
- apply_filters( comment_feed_limits )filterline 2879 (+985 into the body)
Filters the LIMIT clause of the comments feed query before sending.
- apply_filters( posts_where_paged )filterline 2936 (+1042 into the body)
Filters the WHERE clause of the query.
- apply_filters( posts_groupby )filterline 2946 (+1052 into the body)
Filters the GROUP BY clause of the query.
- apply_filters( posts_join_paged )filterline 2958 (+1064 into the body)
Filters the JOIN clause of the query.
- apply_filters( posts_orderby )filterline 2968 (+1074 into the body)
Filters the ORDER BY clause of the query.
- apply_filters( posts_distinct )filterline 2978 (+1084 into the body)
Filters the DISTINCT clause of the query.
- apply_filters( post_limits )filterline 2988 (+1094 into the body)
Filters the LIMIT clause of the query.
- apply_filters( posts_fields )filterline 2998 (+1104 into the body)
Filters the SELECT clause of the query.
- apply_filters( posts_clauses )filterline 3021 (+1127 into the body)
Filters all query clauses at once, for convenience.
- do_action( posts_selection )actionline 3041 (+1147 into the body)
Fires to announce the query's current selection parameters.
- apply_filters( posts_where_request )filterline 3058 (+1164 into the body)
Filters the WHERE clause of the query.
- apply_filters( posts_groupby_request )filterline 3070 (+1176 into the body)
Filters the GROUP BY clause of the query.
- apply_filters( posts_join_request )filterline 3082 (+1188 into the body)
Filters the JOIN clause of the query.
- apply_filters( posts_orderby_request )filterline 3094 (+1200 into the body)
Filters the ORDER BY clause of the query.
- apply_filters( posts_distinct_request )filterline 3106 (+1212 into the body)
Filters the DISTINCT clause of the query.
- apply_filters( posts_fields_request )filterline 3118 (+1224 into the body)
Filters the SELECT clause of the query.
- apply_filters( post_limits_request )filterline 3130 (+1236 into the body)
Filters the LIMIT clause of the query.
- apply_filters( posts_clauses_request )filterline 3155 (+1261 into the body)
Filters all query clauses at once, for convenience.
- apply_filters( posts_request )filterline 3208 (+1314 into the body)
Filters the completed SQL query before sending.
- apply_filters( posts_pre_query )filterline 3227 (+1333 into the body)
Filters the posts array before the query takes place.
- apply_filters( split_the_query )filterline 3399 (+1505 into the body)
Filters whether to split the query.
- apply_filters( posts_request_ids )filterline 3421 (+1527 into the body)
Filters the Post IDs SQL request before sending.
- apply_filters( posts_results )filterline 3467 (+1573 into the body)
Filters the raw post results array, prior to status checks.
- apply_filters( comment_feed_join )filterline 3472 (+1578 into the body)
Filters the JOIN clause of the comments feed query before sending.
- apply_filters( comment_feed_where )filterline 3475 (+1581 into the body)
Filters the WHERE clause of the comments feed query before sending.
- apply_filters( comment_feed_groupby )filterline 3478 (+1584 into the body)
Filters the GROUP BY clause of the comments feed query before sending.
- apply_filters( comment_feed_orderby )filterline 3482 (+1588 into the body)
Filters the ORDER BY clause of the comments feed query before sending.
- apply_filters( comment_feed_limits )filterline 3486 (+1592 into the body)
Filters the LIMIT clause of the comments feed query before sending.
- apply_filters( the_preview )filterline 3561 (+1667 into the body)
Filters the single post for preview mode.
- apply_filters( the_posts )filterline 3624 (+1730 into the body)
Filters the array of retrieved posts after they've been fetched and internally processed.
Uses · 59
- do_action_ref_array()Calls the callback functions that have been added to an action hook, specifying arguments in an array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- remove_all_filters()Removes all of the callback functions from a filter hook.
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- __()Retrieves the translation of $text.
- get_option()Retrieves an option value based on an option name.
- absint()Converts a value to non-negative integer.
- get_post_type_object()Retrieves a post type object by name.
- sanitize_title_for_query()Sanitizes a title with the 'query' context.
- get_page_by_path()Retrieves a page given its path.
- wp_basename()i18n-friendly version of basename().
- get_post()Retrieves post data given a post ID or post object.
Show all 59
- apply_filters_ref_array()Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
- get_post_types()Gets a list of all registered post type objects.
- get_taxonomies_for_attachments()Retrieves all of the taxonomies that are registered for attachments.
- get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
- get_term_by()Gets all term data from database by term field and data.
- addslashes_gpc()Adds slashes to a string or recursively adds slashes to strings within an array.
- wp_parse_id_list()Cleans up an array, comma- or space-separated list of IDs.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- get_user_by()Retrieves user info by a given field.
- wp_post_mime_type_where()Converts MIME types into SQL.
- esc_sql()Escapes data for use in a MySQL query.
- get_current_user_id()Gets the current user's ID.
- get_post_stati()Gets a list of post statuses.
- current_user_can()Returns whether the current user has the specified capability.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- wp_cache_get_last_changed()Gets last changed date for the specified cache group.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- wp_cache_add()Adds data to the cache, if the cache key doesn't already exist.
- _prime_comment_caches()Adds any comments from the given IDs to the cache that do not already exist in cache.
- do_action()Calls the callback functions that have been added to an action hook.
- _prime_post_parent_id_caches()Prime the cache containing the parent ID of various post objects.
- wp_cache_get_multiple()Retrieves multiple values from the cache in one call.
- _prime_post_caches()Adds any posts from the given IDs to the cache that do not already exist in cache.
- wp_cache_set()Saves the data to the cache.
- wp_cache_add_multiple()Adds multiple values to the cache in one call, if the cache keys don't already exist.
- wp_using_ext_object_cache()Toggles `$_wp_using_ext_object_cache` on and off without directly touching global.
- wp_list_pluck()Plucks a certain field out of each object or array in an array.
- get_post_status()Retrieves the post status based on the post ID.
- get_post_status_object()Retrieves a post status object by name.
- current_time()Retrieves the current time based on specified type.
- get_posts()Retrieves an array of the latest posts, or posts matching the given criteria.
- update_post_caches()Updates post, term, and metadata caches for a list of post objects.
- update_menu_item_cache()Updates post and term caches for all linked objects for a list of menu items.
- wp_queue_posts_for_term_meta_lazyload()Queues posts for lazy-loading of term meta.
- WP_Query::parse_query()Parses a query string and sets query type booleans.
- WP_Query::fill_query_vars()Fills in the query variables, which do not exist within the parameter.
- WP_Meta_Query::__construct()Constructor.
- WP_Date_Query::__construct()Constructor.
- WP_Query::parse_search()Generates SQL for the WHERE clause based on passed search terms.
- WP_Query::parse_tax_query()Parses various taxonomy related query vars.
- WP_Query::set()Sets the value of a query variable.
- WP_Query::parse_order()Parse an 'order' query variable and cast it to ASC or DESC as necessary.
- WP_Query::parse_orderby()Converts the given orderby alias (if allowed) to a properly-prefixed value.
- WP_Query::parse_search_order()Generates SQL for the ORDER BY condition based on passed search terms.
- WP_Query::generate_cache_key()Generates cache key.
- stdClass::__construct()
- WP_Query::set_found_posts()Sets up the amount of found posts and the number of pages (if limit clause was used) for the current query.
Used by · 1
- WP_Query::query()Sets up the WordPress query by parsing query string.
Source code
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'] ) ) {Changelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-query.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.