The main query is set up by WP
class (curiously little known, since there is rarely reason to mess with it). It happens in between WP core finishing load and proceeding to load template, in wp-blog-header.php
.
Note that some nuances of implementation:
WP
class works on a global, set up earlier inwp-settings.php
- the global it works on is
$wp_the_query
, which acts at original instance from which more commonly used$wp_query
is spawned. This two-variable implementation is used for detection if the main query had been modified, among other things.
Related Posts:
- $wp_query initiation?
- Custom archive page based on array of categories and tags
- Tell wordpress to show a single page instead of an archive
- List of the years with posts presented
- Display posts from only one post form in custom query and exclude in main query
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Two loops on archive page
- How to order posts by title after they have already been sorted by category
- Filtering out child category posts from parent category archive not working
- Display if author page is author page of current user
- Filtering posts by archive showing all years
- Creating attachments archive in tags and categories
- Post archive for certain post format
- Creating ‘posts page’ loop based on the page itself
- get_children() Archive Template
- In a WP_Query can I force the results’ is_singular() to be set to false?
- Pagination not working on archive.php template?
- How do I stop the same post showing multiple times in a archive?
- WordPress custom query by archive title
- In Product Category archives how to show Posts having same/similar prod_cat slug structure?
- Show full category tree for a year with all post titles?
- How to allow Readers to Select Post Order?
- Get X posts for all post types on Taxonomy term archive
- How to add archives (with pagination) to page template?
- Main loop querying current template’s info only in custom category archive pages, not my posts
- query only direct child and sub-terms of a current term archive
- the_excerpt() not working in custom archive
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Wp_redirect and sending variables
- Sanitation needed for WP_Query or get_posts calls?
- how does $wpdb differ to WP_Query?
- WP_Query – filter or directly?
- How can I save an array from a random post sequence for later use?
- Does WordPress generate an automatic page for post formats?
- Why is WP-Query spelled like it is?
- Limit search results to exact match
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- Pagination not working Search posts
- How to speed up wp_query, took more 5s to run against 100k posts
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Why I can’t get old posts instead of recent with WP_Query?
- How get posts from a subcategory of a category by name?
- WP_Query orderby breaks when using AJAX?
- Detect featured image among the attached images
- WP_Query arguments to fetch custom post type posts which are in certain category?
- WP_Query loop within WP_Query loop
- Search Posts with Custom Fields as query
- Use query->set or make new query?
- How to fetch only media that was already attached to a post/page?
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- WP_Query won’t retrieve raw HTML?
- Remove a specific category ID from related post
- Ajax load more posts – WP_Query parameters not working
- How to display multiple custom fields with the same meta_key in an ascending order?
- Using the_post_thumbnail resets current loop item ID
- Meta_query with multiple keys and multiple values
- WordPress WP_Query make mysql time out
- Get authors by term id or slug
- Assign Json file to WP_Query
- How do I query for posts by partial meta key?
- WP Query to have sticky posts first, with pagination and having a joint ‘posts per page’ arg with main loop
- New WP_Query calls Pre_get_posts filter twice
- Multisite wp_query & switch_to_blog issue
- How to increase load time of an archive/search page (WP_Query)
- Issue with front page navigation after upgrading to 3.4
- Prevent author bio page from showing in search results
- Changing the default wp_search_stopwords
- WP_Query array key / value pairs?
- Get posts from multiple tax terms
- Tax Query only returns for the first of several terms
- WP_Query offset is returning post from prevois loop
- Tax query is not working!
- How To Keep Search Title the same on paged Results
- Does WP_Query ‘responds’ badly to empty arguments?
- Get next/prev image/attachment in time with date query
- Reordering content using a meta value
- Adding query parameter to archive page returns 404
- Optimising WP_Query with ACF Fields
- WordPress AJAX Request returns 400
- Using wpdb prepare with a variable, turns it into a big string
- SQL to join u3g_users & u3g_meta_value with repeating data
- WP_Query no result if keyword contains number
- WP_QUERY order posts by two combined meta_value dates
- Order by value of Custom Field using url string
- update_post_meta performance in a loop woocommerce
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- query_posts() doesn’t seem to be called in my page
- WP_Query returns empty if meta_query has more than 7 values
- query.php – multiple is_category functions
- How to get several fields from wp_query?
- Overwriting auto-appended NOT IN query in WP_Query
- Pagination not working with WP_Query (creates links but no page)
- WP Query posts__in not working with array
- query_posts with sorting on a custom datestamp
- Conditionals in WP_Query
- Query Posts by date range with fixed beginning and end
- query by meta value then date and not empty meta value
- Is it possible to use WP Query to orderby custom meta value and custom taxonomy?
- Display all custom meta field values from the database using ACF Repeater
- How to efficiently find “duplicate” posts, where the titles are different, using metadata to match posts?