I’m looking real hard at the code around both hooks, and they run one right after the other, with the same arguments, and I just can’t see any meaningful difference.
Theoretically only parse_query
would run, and not pre_get_posts
, if WP_Query::parse_query()
were to be run directly on its own, but WordPress itself never does that. Maybe some plugins do, but I don’t know why they would. Near as I can tell there’s no technical reason to use one over the other, but pre_get_posts
is newer, much more widely used, and much better documented, officially and by third parties. I suspect parse_query
is somewhat vestigial.
I’d suggest using pre_get_posts
. Any code you see using parse_query
should work as-is with pre_get_posts
.
Related Posts:
- How to change posts order on Category and Tag archives?
- How to choose between hooking into per_get_posts or into parse_query
- queried_object using pre_get_posts gets notices and warning
- Elementor posts custom query based on tag [closed]
- Using pre_get_posts with WP_Query
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Hook/action after WP_Query gets posts to query custom tables for post-related meta
- How to uniquely identify queries?
- Changing Posts Per Page and offset with pre_get_posts
- Want to redirect if search query match exact title of any post
- Overriding The Loop with filter or hook
- Slow SQL_CALC_FOUND_ROWS Query
- “pre_get_posts” firing on every query
- Using is_main_query to select custom post type on certain page
- SQL Statement generated by WP_Query not producing expected results
- Sorting Posts by custom field
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- Recommended way to drop a pending query (in pre_get_posts)?
- Single page theme that uses pages for the content
- WordPress custom search form with pre_get_posts not work
- order by multiple meta keys in pre_get_posts
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Using pre_get_posts on a specific core/query block
- Best practice custom function, where to echo the variables?
- Searching through different categories on different pages code is not working
- How to display future posts – modified query still yields 404
- Including only current user’s posts in search
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- is_search was called incorrectly
- Formulate a url to show posts with both taxonomy terms
- Offset Page Loops and Pagination
- pre_get_posts order by not working
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- How to use filter hook “the_posts” with a function that refers to $this?
- Store sticky post’s ids in a transient
- How to change main query based on post meta
- new WP_Query to get max price meta value not working
- Display posts from only one post form in custom query and exclude in main query
- Show Sticky Post at the top but do not show again in the loop?
- WP_Query, pre_get_posts and offset
- Complex WP SQL Query
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Show scheduled posts in main loop but not in WP_Query?
- Set global $wp_query/$post variable for dynamic page generation
- hide custom post types with specific meta key ON admin backend
- Filtering out child category posts from parent category archive not working
- Order ascending is ignored in meta query?
- Shouldn’t I be able to modify the main query by this filter?
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- using pre_get_posts for search results not found
- Hide elements outside loop based on query
- How can I override one post and make it display content for another post?
- Woocommerce – exclude only older out-of-stock items
- WP Query – order posts by meta field first and then order the rest
- pre_get_posts – Trying to get property of non-object warning
- date_query in pre_get_posts out of memory
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- WP_Query – How to get all posts of specific days of week by custom field date?
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- How to apply pre_get_posts to a custom query?
- tax_query in pre_get_posts
- $wp_query->found_posts not returning correct value
- WP_Query, Paginate by Custom Field
- WP_Query retuning empty array in rest api
- Exclude post with taxonomy and from the terms (taxonomy & tag) posts count
- Replace wp_query with wp_user_query
- Block internal search queries with pre_get_posts and regex rules
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- is_user_logged_in not working from WP-API (wp-json)
- Search Exact on WordPress – Relevannsi Solution Not Working
- Excluding posts from search results page with meta query not working
- pre_user_query vs pre_get_posts
- Can I alter the main loop to ‘orderby’ a custom callback?
- order posts by a secondary query that counts items
- How can I re-query post_type and rewrite the url?
- Woocomerce – Order products by float attribute in archive pages
- Order posts by title and custom field value?
- Limit default Search query to post_title
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Modify query to exclude certain ids and certain parents and its corresponding children
- Rewrite rule pagination on different url levels
- Adding a Theme Customizer Control for Posts_Per_Page
- pre_get_posts or $where, which one to use?
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- Looking for a way to exclude frontpage and nav menu from query filter
- pre_get_posts redirecting
- Custom post types loop on a page template
- Pre_get_post on CPT archive page
- Search query alteration not working for meta values
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- When to use WP_query(), query_posts() and pre_get_posts
- How to short circuit a wordpress query that is not related to posts?
- get_meta_sql hook is not firing