WP_Query::get_posts(): WP_Post[]|int[]
- Since
- 1.5.0
- Source
wp-includes/class-wp-query.php:1900
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
- 471–571
- 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 3312.
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 | 471–503 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), get_option() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 476–508 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 478–508 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 483–513 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 487–519 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), get_option(), array_map(), reset() |
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false | 492–524 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 494–524 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 499–529 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 504–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 504–539 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 509–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 509–544 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), get_option(), array_map(), wp_list_pluck(), _prime_post_caches(), reset(), wp_queue_posts_for_term_meta_lazyload() |
20 further outcomes, up to 571 instructions
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false && $unfiltered_posts === false | 511–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 511–544 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 512–525 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 516–546 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 516–549 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 517–530 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 519–530 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 524–535 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 528–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 533–546 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 535–546 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 540–551 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 545–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 545–561 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 550–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 550–566 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 552–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(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 552–566 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 557–568 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 557–571 | ->parse_query(), ->fill_query_vars(), apply_filters(), remove_all_filters(), do_action_ref_array(), ->parse_query_vars(), serialize(), md5(), get_option(), ->parse_order(), urldecode(), wp_slash(), explode(), get_post_type_object(), get_post_type_object(), get_current_user_id(), do_action(), strtoupper(), wp_cache_get_last_changed(), 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 | 3308 | 470–570 | 352 | 4 fewer instructions than PHP 8.5 |
| 8.5 | 3312 | 471–571 | 352 | |
| 8.4 | 3312 | 471–571 | 352 | 132 fewer instructions than PHP 8.3 |
| 8.3 | 3444 | 482–582 | 352 | |
| 8.2 | 3444 | 482–582 | 352 | 1 more instruction than PHP 8.1 |
| 8.1 | 3443 | 482–582 | 352 | 11 fewer instructions than PHP 7.4 |
| 7.4 | 3454 | 482–582 | 352 |
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 1916 (+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 1931 (+31 into the body)
Filters whether an attachment query should include filenames or not.
- apply_filters( posts_search )filterline 2297 (+397 into the body)
Filters the search SQL that is used in the WHERE clause of WP_Query.
- apply_filters( posts_search_orderby )filterline 2574 (+674 into the body)
Filters the ORDER BY used when ordering search results.
- apply_filters( posts_where )filterline 2796 (+896 into the body)
Filters the WHERE clause of the query.
- apply_filters( posts_join )filterline 2806 (+906 into the body)
Filters the JOIN clause of the query.
- apply_filters( comment_feed_join )filterline 2847 (+947 into the body)
Filters the JOIN clause of the comments feed query before sending.
- apply_filters( comment_feed_where )filterline 2857 (+957 into the body)
Filters the WHERE clause of the comments feed query before sending.
- apply_filters( comment_feed_groupby )filterline 2867 (+967 into the body)
Filters the GROUP BY clause of the comments feed query before sending.
- apply_filters( comment_feed_orderby )filterline 2877 (+977 into the body)
Filters the ORDER BY clause of the comments feed query before sending.
- apply_filters( comment_feed_limits )filterline 2887 (+987 into the body)
Filters the LIMIT clause of the comments feed query before sending.
- apply_filters( posts_where_paged )filterline 2947 (+1047 into the body)
Filters the WHERE clause of the query.
- apply_filters( posts_groupby )filterline 2957 (+1057 into the body)
Filters the GROUP BY clause of the query.
- apply_filters( posts_join_paged )filterline 2969 (+1069 into the body)
Filters the JOIN clause of the query.
- apply_filters( posts_orderby )filterline 2979 (+1079 into the body)
Filters the ORDER BY clause of the query.
- apply_filters( posts_distinct )filterline 2989 (+1089 into the body)
Filters the DISTINCT clause of the query.
- apply_filters( post_limits )filterline 2999 (+1099 into the body)
Filters the LIMIT clause of the query.
- apply_filters( posts_fields )filterline 3009 (+1109 into the body)
Filters the SELECT clause of the query.
- apply_filters( posts_clauses )filterline 3032 (+1132 into the body)
Filters all query clauses at once, for convenience.
- do_action( posts_selection )actionline 3052 (+1152 into the body)
Fires to announce the query's current selection parameters.
- apply_filters( posts_where_request )filterline 3069 (+1169 into the body)
Filters the WHERE clause of the query.
- apply_filters( posts_groupby_request )filterline 3081 (+1181 into the body)
Filters the GROUP BY clause of the query.
- apply_filters( posts_join_request )filterline 3093 (+1193 into the body)
Filters the JOIN clause of the query.
- apply_filters( posts_orderby_request )filterline 3105 (+1205 into the body)
Filters the ORDER BY clause of the query.
- apply_filters( posts_distinct_request )filterline 3117 (+1217 into the body)
Filters the DISTINCT clause of the query.
- apply_filters( posts_fields_request )filterline 3129 (+1229 into the body)
Filters the SELECT clause of the query.
- apply_filters( post_limits_request )filterline 3141 (+1241 into the body)
Filters the LIMIT clause of the query.
- apply_filters( posts_clauses_request )filterline 3166 (+1266 into the body)
Filters all query clauses at once, for convenience.
- apply_filters( posts_request )filterline 3219 (+1319 into the body)
Filters the completed SQL query before sending.
- apply_filters( posts_pre_query )filterline 3238 (+1338 into the body)
Filters the posts array before the query takes place.
- apply_filters( split_the_query )filterline 3416 (+1516 into the body)
Filters whether to split the query.
- apply_filters( posts_request_ids )filterline 3438 (+1538 into the body)
Filters the Post IDs SQL request before sending.
- apply_filters( posts_results )filterline 3484 (+1584 into the body)
Filters the raw post results array, prior to status checks.
- apply_filters( comment_feed_join )filterline 3489 (+1589 into the body)
Filters the JOIN clause of the comments feed query before sending.
- apply_filters( comment_feed_where )filterline 3492 (+1592 into the body)
Filters the WHERE clause of the comments feed query before sending.
- apply_filters( comment_feed_groupby )filterline 3495 (+1595 into the body)
Filters the GROUP BY clause of the comments feed query before sending.
- apply_filters( comment_feed_orderby )filterline 3499 (+1599 into the body)
Filters the ORDER BY clause of the comments feed query before sending.
- apply_filters( comment_feed_limits )filterline 3503 (+1603 into the body)
Filters the LIMIT clause of the comments feed query before sending.
- apply_filters( the_preview )filterline 3578 (+1678 into the body)
Filters the single post for preview mode.
- apply_filters( the_posts )filterline 3641 (+1741 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.
- wp_slash()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.
- array_last()Polyfill for `array_last()` function added in PHP 8.5.
- 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_salted()Retrieves cached data if valid and unchanged.
- wp_cache_set_salted()Stores salted data in the cache.
- _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_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. `$query->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 ) ); // Locally scoped reference for easy of use. $query_vars = &$this->query_vars; // Fill again in case 'pre_get_posts' unset some vars. $query_vars = $this->fill_query_vars( $query_vars ); /** * 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( $query_vars ); // 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( $query_vars['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( $query_vars['ignore_sticky_posts'] ) ) { $query_vars['ignore_sticky_posts'] = $query_vars['caller_get_posts']; } } if ( ! isset( $query_vars['ignore_sticky_posts'] ) ) { $query_vars['ignore_sticky_posts'] = false; } if ( ! isset( $query_vars['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 7.1.0 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.