You are invoking an infinite loop, because you are calling WP_Query
inside WP_Query
, which is where the hook resides, so you are hooking it into parse_query
over and over again. To avoid it, put the following at the beginning of your callback function:
// avoid infinite loop
remove_action( 'parse_query', __FUNCTION__ );
Additional note, it might just be a lesser technicality, but in my mind the right hook to use would be pre_get_posts
.
Related Posts:
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to uniquely identify queries?
- pre_get_posts with get_posts
- Can not switch the queried post in pre_get_posts hook
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- pre_get_posts – Trying to get property of non-object warning
- `offset` WP_Query argument dont work via `pre_get_posts`
- pre_user_query vs pre_get_posts
- Using the same WP_Query for shop and widgets in WooCommerce shop
- wp_query – Modify $query to include duplicate content
- Custom post types loop on a page template
- Pre_get_post on CPT archive page
- Search query alteration not working for meta values
- When to use WP_query(), query_posts() and pre_get_posts
- Return only Count from a wp_query request?
- How to add taxonomy filter on the query fly?
- Make a WP Query search match exactly the search term
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Query WooCommerce orders where meta data does not exist
- author.php with ACF and CPTs
- Query Custom Meta Value with Increment
- RSS feed with specific keyword
- Identify which loop you are hooking into; primary or secondary?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- How to get the posts published in last two days using WP_Query?
- Query with pre_get_posts to get pagination
- Dynamically Override Fancy Title – Part II
- Transient pagination not working properly
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- view queries made?
- Pass the same object to multiple widgets in a template with one query
- Get the post permalink within the loop but without additional DB query
- WP_Tax_Query with post_tag not working
- List the 5 most recent child pages
- pre_get_posts filter meta_query without conflicting existing meta_query
- How to change posts order on Category and Tag archives?
- My Main Query Modification is Messing up my dynamic main – why?
- Query total number of posts
- Creating a custom search for a specific post type
- How to query a custom post type with a taxonomy filter but display post type archive page?
- Change query_posts to WP_Query in page but does not work
- Optional Meta Query
- Set conditional on template based on referring page slug
- Iterating through $wpdb query without using get_results for large query results
- Weird orderby => post__in issue
- Filter posts in category archive page by year using a dropdown
- Set global $wp_query/$post variable for dynamic page generation
- Include data from custom table in WP_Query
- Meta Query relation “AND” then set array accordingly
- How to get a query variable?
- date_query seems to be ignored by wp_query
- Better wordpress attachment query than this
- Is it possible to query from external database? [duplicate]
- Can’t sort custom post type by random
- Query posts that contain video?
- Show a 404 error page if Public query variable’s value doesn’t exist?
- How to set up hierarchical relationships without using plugins / meta query
- Set front_page programatically after user login via query, while leaving site option alone
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- mysql query order by
- Notice thrown when creating numeric pagination on custom query
- wordpress udpate query not equal to
- tax_query in pre_get_posts
- meta_query where the meta value is not the post title
- Elementor posts custom query based on tag [closed]
- Exclude post with taxonomy and from the terms (taxonomy & tag) posts count
- Multi-layered WP_Query
- Pagination of custom page with custom fields query
- pre_get_posts pagination not working
- Woocommerce Get Orders By Meta Value
- meta_query is overriding default search
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- How to query 5 users in random who have published more than 10 posts
- Order posts by title and custom field value?
- Is my code correct?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Meta query doesn’t remove placeholder escape before query
- How to show post title in content editor in backend?
- What is the best way to reset a search on a meta_key / meta_value?
- why doesn’t this pre_get_posts code work?
- pre_get_posts with WP_Query to prevent posts from specific tags
- How can I modify standard search query to include also ACF custom fields values?
- Bring a post to the top of the query if it’s in a certain category?
- WP_Query with child element
- How to get query results for the next page
- Order posts by custom column using pre_get_posts
- Using WP_Query to re-query and sort results using a date?
- Pagination is not working on custom query inside a custom home page template
- Loop through multiple custom fields with increasing number
- How to organize a WP_Query’s list of posts by category and display category title?
- Need help setting up a search form for wordpress [duplicate]
- WordPress Query showing multiple titles
- custom query to get posts
- confirm my booking with phone number
- pre_get_posts redirecting
- Get WP_Query query after execution?
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- Advanced Search – Is this possible?