wppaste
WordPress

WP_Query::get_posts(): WP_Post[]|int[]

Since
1.5.0
Source
wp-includes/class-wp-query.php:1894
Retrieves an array of posts based on query variables.

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

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
463–563

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 3324.

Plugin surface
35 hooks

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.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action_ref_array()called directly
  • optionoption read or writeget_option()called directly
  • querycontent queryget_post()called directly
  • cacheobject cachewp_cache_get_last_changed()called directly
  • serializeserialisationserialize()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.

WhenInstructionsCalls it makes
$hash === false && explode() && !is_array($post_type) && $post_type !== "any" && empty($post_type) && empty($groupby) && $fields && $old_request !== false463–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 !== false468–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 !== false470–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 !== false475–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 !== false479–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 !== false484–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 !== false486–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 !== false491–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 === false496–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 !== false496–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 === false501–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 !== false501–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 === false503–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 !== false503–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) && !$i504–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 === false508–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 !== false508–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) && !$i509–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) && !$i511–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) && !$i516–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) && !$i520–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) && !$i525–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) && !$i527–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) && !$i532–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 === false537–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) && !$i537–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 === false542–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) && !$i542–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 === false544–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) && !$i544–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 === false549–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) && !$i549–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

PHPCompiledExecutedBranchesNotes
8.6-dev3320462–5623514 fewer instructions than PHP 8.5
8.53324463–563351
8.43324463–563351132 fewer instructions than PHP 8.3
8.33456474–574351
8.23456474–5743511 more instruction than PHP 8.1
8.13455474–57435125 fewer instructions than PHP 7.4
7.43480474–574351

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:

  1. 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.

  2. apply_filters( wp_allow_query_attachment_by_filename )filterline 1925 (+31 into the body)

    Filters whether an attachment query should include filenames or not.

  3. apply_filters( posts_search )filterline 2291 (+397 into the body)

    Filters the search SQL that is used in the WHERE clause of WP_Query.

  4. apply_filters( posts_search_orderby )filterline 2566 (+672 into the body)

    Filters the ORDER BY used when ordering search results.

  5. apply_filters( posts_where )filterline 2788 (+894 into the body)

    Filters the WHERE clause of the query.

  6. apply_filters( posts_join )filterline 2798 (+904 into the body)

    Filters the JOIN clause of the query.

  7. apply_filters( comment_feed_join )filterline 2839 (+945 into the body)

    Filters the JOIN clause of the comments feed query before sending.

  8. apply_filters( comment_feed_where )filterline 2849 (+955 into the body)

    Filters the WHERE clause of the comments feed query before sending.

  9. apply_filters( comment_feed_groupby )filterline 2859 (+965 into the body)

    Filters the GROUP BY clause of the comments feed query before sending.

  10. apply_filters( comment_feed_orderby )filterline 2869 (+975 into the body)

    Filters the ORDER BY clause of the comments feed query before sending.

  11. apply_filters( comment_feed_limits )filterline 2879 (+985 into the body)

    Filters the LIMIT clause of the comments feed query before sending.

  12. apply_filters( posts_where_paged )filterline 2936 (+1042 into the body)

    Filters the WHERE clause of the query.

  13. apply_filters( posts_groupby )filterline 2946 (+1052 into the body)

    Filters the GROUP BY clause of the query.

  14. apply_filters( posts_join_paged )filterline 2958 (+1064 into the body)

    Filters the JOIN clause of the query.

  15. apply_filters( posts_orderby )filterline 2968 (+1074 into the body)

    Filters the ORDER BY clause of the query.

  16. apply_filters( posts_distinct )filterline 2978 (+1084 into the body)

    Filters the DISTINCT clause of the query.

  17. apply_filters( post_limits )filterline 2988 (+1094 into the body)

    Filters the LIMIT clause of the query.

  18. apply_filters( posts_fields )filterline 2998 (+1104 into the body)

    Filters the SELECT clause of the query.

  19. apply_filters( posts_clauses )filterline 3021 (+1127 into the body)

    Filters all query clauses at once, for convenience.

  20. do_action( posts_selection )actionline 3041 (+1147 into the body)

    Fires to announce the query's current selection parameters.

  21. apply_filters( posts_where_request )filterline 3058 (+1164 into the body)

    Filters the WHERE clause of the query.

  22. apply_filters( posts_groupby_request )filterline 3070 (+1176 into the body)

    Filters the GROUP BY clause of the query.

  23. apply_filters( posts_join_request )filterline 3082 (+1188 into the body)

    Filters the JOIN clause of the query.

  24. apply_filters( posts_orderby_request )filterline 3094 (+1200 into the body)

    Filters the ORDER BY clause of the query.

  25. apply_filters( posts_distinct_request )filterline 3106 (+1212 into the body)

    Filters the DISTINCT clause of the query.

  26. apply_filters( posts_fields_request )filterline 3118 (+1224 into the body)

    Filters the SELECT clause of the query.

  27. apply_filters( post_limits_request )filterline 3130 (+1236 into the body)

    Filters the LIMIT clause of the query.

  28. apply_filters( posts_clauses_request )filterline 3155 (+1261 into the body)

    Filters all query clauses at once, for convenience.

  29. apply_filters( posts_request )filterline 3208 (+1314 into the body)

    Filters the completed SQL query before sending.

  30. apply_filters( posts_pre_query )filterline 3227 (+1333 into the body)

    Filters the posts array before the query takes place.

  31. apply_filters( split_the_query )filterline 3399 (+1505 into the body)

    Filters whether to split the query.

  32. apply_filters( posts_request_ids )filterline 3421 (+1527 into the body)

    Filters the Post IDs SQL request before sending.

  33. apply_filters( posts_results )filterline 3467 (+1573 into the body)

    Filters the raw post results array, prior to status checks.

  34. apply_filters( comment_feed_join )filterline 3472 (+1578 into the body)

    Filters the JOIN clause of the comments feed query before sending.

  35. apply_filters( comment_feed_where )filterline 3475 (+1581 into the body)

    Filters the WHERE clause of the comments feed query before sending.

  36. apply_filters( comment_feed_groupby )filterline 3478 (+1584 into the body)

    Filters the GROUP BY clause of the comments feed query before sending.

  37. apply_filters( comment_feed_orderby )filterline 3482 (+1588 into the body)

    Filters the ORDER BY clause of the comments feed query before sending.

  38. apply_filters( comment_feed_limits )filterline 3486 (+1592 into the body)

    Filters the LIMIT clause of the comments feed query before sending.

  39. apply_filters( the_preview )filterline 3561 (+1667 into the body)

    Filters the single post for preview mode.

  40. 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

Show all 59

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.