Title: Query
Author: Andrew Nacin
Published: January 29, 2014
Last modified: July 16, 2025

---

## Query component

The Query component includes the following:

 * `WP_Query`, `WP_User_Query`, and `WP_Comment_Query`. These are the three APIs
   that WordPress offers for constructing complex data queries.
 * Template functions used to deterimine the kind of page currently being requested.
   These are the `is_*()` functions – `is_month()`, `is_single()`, and so on.
 * `WP_Meta_Query`, `WP_Tax_Query`, and `WP_Date_Query`. These are helper classes,
   used by the main query classes as well as third-party plugins, to construct SQL
   clauses related to metadata, taxonomyTaxonomy A taxonomy is a way to group things
   together. In WordPress, some common taxonomies are category, link, tag, or post
   format. [https://codex.wordpress.org/Taxonomies#Default_Taxonomies](https://codex.wordpress.org/Taxonomies#Default_Taxonomies).
   terms, and date ranges.

### Projects for future releases

 * Improved caching. Most queries are currently cached at the level of individual
   items (posts, users, etc), but the IDs that result from the query are uncached.
   See [#22176](https://core.trac.wordpress.org/ticket/22176) for an example.
 * The query classes, and particularly `WP_Query`, contain lots of legacy code that
   causes problems in edge cases, makes unit testing difficult, and so on. There
   are various initiatives underway to clean up some of these problems. See [#30911](https://core.trac.wordpress.org/ticket/30911)
   for an example related to `post_status`.

 

### Recent posts on the make/core blog

 * [Expanded meta key comparison operators in 5.3](https://make.wordpress.org/core/2019/10/15/expanded-meta-key-comparison-operators-in-5-3/)(
   October 15, 2019)
 * [LIKE support for meta keys in 5.1](https://make.wordpress.org/core/2019/01/23/like-support-for-meta-keys-in-5-1/)(
   January 23, 2019)
 * [Query component bug scrub – May 24](https://make.wordpress.org/core/2016/05/18/query-component-bug-scrub-may-24/)(
   May 18, 2016)
 * [Query improvements in WP 4.2: ‘orderby’ and ‘meta_query’](https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/)(
   March 30, 2015)
 * [Update on Query improvements in 4.1](https://make.wordpress.org/core/2014/10/20/update-on-query-improvements-in-4-1/)(
   October 20, 2014)

View all posts tagged [query](https://make.wordpress.org/core/tag/query/).

[Create a new ticket](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fcore.trac.wordpress.org%2Fnewticket%3Fcomponent%3DQuery)

### 276 open tickets in the Query component

| [276 open tickets](https://core.trac.wordpress.org/query?component=Query&status=!closed) | [defect (bug)](https://core.trac.wordpress.org/query?component=Query&type=defect+%28bug%29&group=milestone&status=!closed) | [enhancement](https://core.trac.wordpress.org/query?component=Query&type=enhancement&group=milestone&status=!closed) | [feature request](https://core.trac.wordpress.org/query?component=Query&type=feature+request&group=milestone&status=!closed) | 
| [](https://core.trac.wordpress.org/query?component=Query&milestone&group=task+%28blessed%29&status=!closed) | [24](https://core.trac.wordpress.org/query?component=Query&milestone&type=defect+%28bug%29&status=!closed) | [30](https://core.trac.wordpress.org/query?component=Query&milestone&type=enhancement&status=!closed) | [2](https://core.trac.wordpress.org/query?component=Query&milestone&type=feature+request&status=!closed) | 
| [7.2](https://core.trac.wordpress.org/query?component=Query&milestone=7.2&group=task+%28blessed%29&status=!closed) | [1](https://core.trac.wordpress.org/query?component=Query&milestone=7.2&type=defect+%28bug%29&status=!closed) | 0 | 0 | 
| [Awaiting Review](https://core.trac.wordpress.org/query?component=Query&milestone=Awaiting+Review&group=task+%28blessed%29&status=!closed) | [119](https://core.trac.wordpress.org/query?component=Query&milestone=Awaiting+Review&type=defect+%28bug%29&status=!closed) | [34](https://core.trac.wordpress.org/query?component=Query&milestone=Awaiting+Review&type=enhancement&status=!closed) | [12](https://core.trac.wordpress.org/query?component=Query&milestone=Awaiting+Review&type=feature+request&status=!closed) | 
| [Future Release](https://core.trac.wordpress.org/query?component=Query&milestone=Future+Release&group=task+%28blessed%29&status=!closed) | [32](https://core.trac.wordpress.org/query?component=Query&milestone=Future+Release&type=defect+%28bug%29&status=!closed) | [19](https://core.trac.wordpress.org/query?component=Query&milestone=Future+Release&type=enhancement&status=!closed) | [3](https://core.trac.wordpress.org/query?component=Query&milestone=Future+Release&type=feature+request&status=!closed) |

 **276 open tickets.** Last 7 days: +0 tickets

### 61 tickets that have no replies

[View list on Trac](https://core.trac.wordpress.org/query?component=Query&id=30994%2C36309%2C36670%2C36966%2C37489%2C39632%2C39914%2C40300%2C40327%2C40903%2C40984%2C41678%2C41843%2C42082%2C42732%2C43324%2C43445%2C43634%2C44372%2C44519%2C44602%2C45376%2C45400%2C46285%2C46347%2C47009%2C47211%2C47493%2C47694%2C48020%2C48029%2C48768%2C49057%2C49168%2C49555%2C49911%2C51794%2C52971%2C54268%2C54436%2C55649%2C55748%2C56081%2C56168%2C57303%2C57412%2C57505%2C57766%2C58447%2C58553%2C58806%2C60027%2C60154%2C60274%2C60468%2C60490%2C60963%2C60984%2C61621%2C63094%2C63106&status=!closed)

 * [#30994](https://core.trac.wordpress.org/ticket/30994)  Offset return for wp_get_archives
 * [#36309](https://core.trac.wordpress.org/ticket/36309)  Timezone issue in WP_Date_Query-
   >build_mysql_datetime
 * [#36670](https://core.trac.wordpress.org/ticket/36670)  Move CAST to right-hand
   side of comparison in meta query
 * [#36966](https://core.trac.wordpress.org/ticket/36966)  Search is not working
   with soft hyphen symbols
 * [#37489](https://core.trac.wordpress.org/ticket/37489)  If Posts have the same
   datetime, the order of the post is indefinite.
 * [#39632](https://core.trac.wordpress.org/ticket/39632)  Adding Query identifier
   attribute ui
 * [#39914](https://core.trac.wordpress.org/ticket/39914)  'orderby' date results
   differs depend on 'post_status'
 * [#40300](https://core.trac.wordpress.org/ticket/40300)  `title` parameter causes`
   WP_Query` to return sticky posts.
 * [#40327](https://core.trac.wordpress.org/ticket/40327)  Wrong SQL request for'
   EXIST' OR 'NOT EXIST' on same post meta
 * [#40903](https://core.trac.wordpress.org/ticket/40903)  Filtered posts_request
   query can break found_posts query
 * [#40984](https://core.trac.wordpress.org/ticket/40984)  Possible Bug with Named
   Orderby Meta Query SQL
 * [#41678](https://core.trac.wordpress.org/ticket/41678)  Make sure all field returns
   use filters in WP Query
 * [#41843](https://core.trac.wordpress.org/ticket/41843)  Provide more flexibility
   to the `get_{$adjacent}_post_where` hook
 * [#42082](https://core.trac.wordpress.org/ticket/42082)  Support compare custom
   fields in WP_Meta_Query
 * [#42732](https://core.trac.wordpress.org/ticket/42732)  Problem with usage of
   WP_Term_Query inside WP_Tax_Query
 * [#43324](https://core.trac.wordpress.org/ticket/43324)  query_vars is not necessarely
   representative of the final query_vars used to build the SQL query
 * [#43445](https://core.trac.wordpress.org/ticket/43445)  Wildcard `LIKE` support
   for `WP_Meta_Query` (and maybe other queries?)
 * [#43634](https://core.trac.wordpress.org/ticket/43634)  WP_Query returns wrong
   result if 10+ search terms and all negative.
 * [#44372](https://core.trac.wordpress.org/ticket/44372)  WP_Query cannot properly
   order by nested Parent/Child relationships
 * [#44519](https://core.trac.wordpress.org/ticket/44519)  Where are the pages of
   the headings added with the + add-on (any) ala https://wp-kama.ru/cat/wordpress/
   codex+xxx
 * [#44602](https://core.trac.wordpress.org/ticket/44602)  meta_query to support
   FIND_IN_SET
 * [#45376](https://core.trac.wordpress.org/ticket/45376)  Search not working as
   described in codex
 * [#45400](https://core.trac.wordpress.org/ticket/45400)  last of query_vars contains
   anchor
 * [#46285](https://core.trac.wordpress.org/ticket/46285)  Search colums of WP User
   Query vars is not updated after applying user_search_columns filter
 * [#46347](https://core.trac.wordpress.org/ticket/46347)  WP_Term_Query where sql_clauses
   oddity
 * [#47009](https://core.trac.wordpress.org/ticket/47009)  WP_Query bug with author
   =0
 * [#47211](https://core.trac.wordpress.org/ticket/47211)  using amp in search show
   all post / pages with the &
 * [#47493](https://core.trac.wordpress.org/ticket/47493)  Meta Query Sorting with
   relation => OR not behaving as expected
 * [#47694](https://core.trac.wordpress.org/ticket/47694)  Adding a filter for $
   searchand variable
 * [#48020](https://core.trac.wordpress.org/ticket/48020)  Queries display in inconsistent
   order when ordering by meta_value_num
 * [#48029](https://core.trac.wordpress.org/ticket/48029)  WP_Query::query only 
   using a single post_status
 * [#48768](https://core.trac.wordpress.org/ticket/48768)  WordPress 5.3 ajax bug
   with Elementor 2.7.5 javascript
 * [#49057](https://core.trac.wordpress.org/ticket/49057)  Add tag for any WP_Query
   for simple access in pre_get_post action
 * [#49168](https://core.trac.wordpress.org/ticket/49168)  is_post_type_archive(
   $post_types = '' ) doesn't work with underscore (_) template
 * [#49555](https://core.trac.wordpress.org/ticket/49555)  Reorder WP_Query methods
   for a more logical placement
 * [#49911](https://core.trac.wordpress.org/ticket/49911)  WP_Tax_Query generates
   incorrect SQL
 * [#51794](https://core.trac.wordpress.org/ticket/51794)  An author_name query 
   with nonexistent user returns posts with no author
 * [#52971](https://core.trac.wordpress.org/ticket/52971)  WP_Query's meta_query
   With Multiple EXISTS keys and OR Relation Doesn't Work Properly
 * [#54268](https://core.trac.wordpress.org/ticket/54268)  Using `author_name` in
   URL parameter gives unexpected results when logged into contributor account administration
 * [#54436](https://core.trac.wordpress.org/ticket/54436)  Sorting issue- when sorting
   via a custom meta key
 * [#55649](https://core.trac.wordpress.org/ticket/55649)  Block Query with full
   post content do not display properly
 * [#55748](https://core.trac.wordpress.org/ticket/55748)  wp_query post_type taxonomies
   doesn't accept array in url if hierarchical
 * [#56081](https://core.trac.wordpress.org/ticket/56081)  Query Loop block with
   selection causes Sticky Posts setting to be ignored
 * [#56168](https://core.trac.wordpress.org/ticket/56168)  Add a way easily perform
   advanced post fields queries
 * [#57303](https://core.trac.wordpress.org/ticket/57303)  wp_get_posts() for post_type
   ="any" + post__in creates not optimized database query performance
 * [#57412](https://core.trac.wordpress.org/ticket/57412)  Uncaught TypeError: Cannot
   read properties of undefined (reading 'length'): jquery migrate
 * [#57505](https://core.trac.wordpress.org/ticket/57505)  category archive url 
   ending with "/0" should be 404
 * [#57766](https://core.trac.wordpress.org/ticket/57766)  filter query_loop_block_query_vars
   repeater 4 times
 * [#58447](https://core.trac.wordpress.org/ticket/58447)  Posts with ‘Stick to 
   the top of the blog’ should also stick to the top of the categories it belongs
   to
 * [#58553](https://core.trac.wordpress.org/ticket/58553)  Two query blocks on home
   template (FSE) breaks the second one
 * [#58806](https://core.trac.wordpress.org/ticket/58806)  Unexpected ordering result
   when ordering based on multiple clauses
 * [#60027](https://core.trac.wordpress.org/ticket/60027)  Post patterns show no
   posts
 * [#60154](https://core.trac.wordpress.org/ticket/60154)  Add filter hook to either
   get_post_stati or WP_List_Util::filter
 * [#60274](https://core.trac.wordpress.org/ticket/60274)  Query loop showing too
   many posts
 * [#60468](https://core.trac.wordpress.org/ticket/60468)  WP_Query matches any 
   post when query parameter "name" is an empty string
 * [#60490](https://core.trac.wordpress.org/ticket/60490)  Add 'author__in' option
   to WP_Query 'orderby' options
 * [#60963](https://core.trac.wordpress.org/ticket/60963)  Custom query, inherit
   main query, show scheduled posts
 * [#60984](https://core.trac.wordpress.org/ticket/60984)  WP_Query is returning
   the two same post instead of one
 * [#61621](https://core.trac.wordpress.org/ticket/61621)  WP_Query get_posts should
   be call its property not again execute all caculations
 * [#63094](https://core.trac.wordpress.org/ticket/63094)  Allow ordering by meta_id
   in a meta query
 * [#63106](https://core.trac.wordpress.org/ticket/63106)  The loop can throw warning
   if `WP_Query::have_posts()` not called.

### 1 ticket slated for 7.2

[View list in Trac](https://core.trac.wordpress.org/query?component=Query&milestone=7.2&status=!closed)

 * [#64130](https://core.trac.wordpress.org/ticket/64130)  Type error in /wp-includes/
   class-wpdb.php

### 276 open tickets

**Open enhancements: 83** [View list on Trac](https://core.trac.wordpress.org/query?component=Query&type=enhancement&status=!closed)
**
Open tasks: 0** [View list on Trac](https://core.trac.wordpress.org/query?component=Query&type=task+%28blessed%29&status=!closed)**
Open feature requests: 17** [View list on Trac](https://core.trac.wordpress.org/query?component=Query&type=feature+request&status=!closed)**
Open defects: 176** [View list on Trac](https://core.trac.wordpress.org/query?component=Query&type=defect+%28bug%29&status=!closed)

### Help maintain this component

Many contributors help maintain one or more components. These maintainers are vital
to keeping WordPress development running as smoothly as possible. They triage new
tickets, look after existing ones, spearhead or mentor tasks, pitch new ideas, curate
roadmaps, and provide feedback to other contributors. Longtime maintainers with 
a deep understanding of particular areas of Core are always seeking to mentor others
to impart their knowledge.

**Want to help? Start following this component!** [Adjust your notifications here](https://make.wordpress.org/core/notifications/?output_format=md).
Feel free to dig into any ticket.

Contributors following this component:

 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 