The split_the_query
Hook in WPFTS
The split_the_query
hook in WordPress is a filter that allows developers to enable or disable the split query mode in WP_Query
. In this mode, WordPress first executes a query to retrieve post IDs, and then performs a separate query to retrieve the full data for those posts. WPFTS uses this hook to activate the split query in certain cases to optimize search performance.
What WPFTS Does When split_the_query
is Called:
-
Checking Conditions for Split Query: WPFTS checks if the flag
$wpq->wpftsi_session['use_indexed_search']
(indexed search enabled) is set. If indexed search is enabled, the plugin checks if the query has aLIMIT
clause and if the number of requested posts per page (posts_per_page
) does not exceed a certain limit. It also checks if all fields from thewp_posts
table ({$wpdb->posts}.*
) are selected. If all these conditions are met, WPFTS enables split query mode. -
Setting the
is_split_query
Flag: If split query mode is enabled, WPFTS sets the flag$wpq->wpftsi_session['is_split_query']
totrue
. This flag is then used in other parts of the plugin, such as theposts_pre_query
hook, to retrieve the full post data.
Important Functions Involved in split_the_query
Handling:
WPFTS_Search::index_split_the_query()
How to Use This in Addon Development:
Addon developers need to understand how WPFTS manages split query mode. If your addon also interacts with this mode, make sure your logic doesn’t conflict with WPFTS. In particular, be aware that WPFTS may enable the split query automatically depending on the search query parameters.
Additional Notes:
- The split query in WPFTS is used to optimize performance when searching with a large number of results.
- WPFTS enables the split query only under certain conditions to avoid unnecessary complexity and performance degradation in simple cases.