wppaste
WordPress

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

Since
1.5.0
Source
wp-includes/class-wp-query.php:1890
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
471–571

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

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 !== false471–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 !== false476–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 !== false478–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 !== false483–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 !== false487–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 !== false492–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 !== false494–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 !== false499–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 === false504–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 !== false504–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 === false509–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 !== false509–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 === false511–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 !== false511–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) && !$i512–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 === false516–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 !== false516–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) && !$i517–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) && !$i519–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) && !$i524–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) && !$i528–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) && !$i533–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) && !$i535–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) && !$i540–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 === false545–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) && !$i545–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 === false550–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) && !$i550–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 === false552–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) && !$i552–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 === false557–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) && !$i557–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

PHPCompiledExecutedBranchesNotes
8.6-dev3317470–5703524 fewer instructions than PHP 8.5
8.53321471–571352
8.43321471–571352132 fewer instructions than PHP 8.3
8.33453482–582352
8.23453482–5823521 more instruction than PHP 8.1
8.13452482–58235211 fewer instructions than PHP 7.4
7.43463482–582352

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 1906 (+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 1921 (+31 into the body)

    Filters whether an attachment query should include filenames or not.

  3. apply_filters( posts_search )filterline 2287 (+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 2562 (+672 into the body)

    Filters the ORDER BY used when ordering search results.

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

    Filters the WHERE clause of the query.

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

    Filters the JOIN clause of the query.

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

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

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

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

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

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

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

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

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

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

  12. apply_filters( posts_where_paged )filterline 2935 (+1045 into the body)

    Filters the WHERE clause of the query.

  13. apply_filters( posts_groupby )filterline 2945 (+1055 into the body)

    Filters the GROUP BY clause of the query.

  14. apply_filters( posts_join_paged )filterline 2957 (+1067 into the body)

    Filters the JOIN clause of the query.

  15. apply_filters( posts_orderby )filterline 2967 (+1077 into the body)

    Filters the ORDER BY clause of the query.

  16. apply_filters( posts_distinct )filterline 2977 (+1087 into the body)

    Filters the DISTINCT clause of the query.

  17. apply_filters( post_limits )filterline 2987 (+1097 into the body)

    Filters the LIMIT clause of the query.

  18. apply_filters( posts_fields )filterline 2997 (+1107 into the body)

    Filters the SELECT clause of the query.

  19. apply_filters( posts_clauses )filterline 3020 (+1130 into the body)

    Filters all query clauses at once, for convenience.

  20. do_action( posts_selection )actionline 3040 (+1150 into the body)

    Fires to announce the query's current selection parameters.

  21. apply_filters( posts_where_request )filterline 3057 (+1167 into the body)

    Filters the WHERE clause of the query.

  22. apply_filters( posts_groupby_request )filterline 3069 (+1179 into the body)

    Filters the GROUP BY clause of the query.

  23. apply_filters( posts_join_request )filterline 3081 (+1191 into the body)

    Filters the JOIN clause of the query.

  24. apply_filters( posts_orderby_request )filterline 3093 (+1203 into the body)

    Filters the ORDER BY clause of the query.

  25. apply_filters( posts_distinct_request )filterline 3105 (+1215 into the body)

    Filters the DISTINCT clause of the query.

  26. apply_filters( posts_fields_request )filterline 3117 (+1227 into the body)

    Filters the SELECT clause of the query.

  27. apply_filters( post_limits_request )filterline 3129 (+1239 into the body)

    Filters the LIMIT clause of the query.

  28. apply_filters( posts_clauses_request )filterline 3154 (+1264 into the body)

    Filters all query clauses at once, for convenience.

  29. apply_filters( posts_request )filterline 3207 (+1317 into the body)

    Filters the completed SQL query before sending.

  30. apply_filters( posts_pre_query )filterline 3226 (+1336 into the body)

    Filters the posts array before the query takes place.

  31. apply_filters( split_the_query )filterline 3404 (+1514 into the body)

    Filters whether to split the query.

  32. apply_filters( posts_request_ids )filterline 3426 (+1536 into the body)

    Filters the Post IDs SQL request before sending.

  33. apply_filters( posts_results )filterline 3472 (+1582 into the body)

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

  34. apply_filters( comment_feed_join )filterline 3477 (+1587 into the body)

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

  35. apply_filters( comment_feed_where )filterline 3480 (+1590 into the body)

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

  36. apply_filters( comment_feed_groupby )filterline 3483 (+1593 into the body)

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

  37. apply_filters( comment_feed_orderby )filterline 3487 (+1597 into the body)

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

  38. apply_filters( comment_feed_limits )filterline 3491 (+1601 into the body)

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

  39. apply_filters( the_preview )filterline 3566 (+1676 into the body)

    Filters the single post for preview mode.

  40. apply_filters( the_posts )filterline 3629 (+1739 into the body)

    Filters the array of retrieved posts after they've been fetched and internally processed.

Uses · 58

Show all 58

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. `$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.

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