The posts_join
Hook in WPFTS
The posts_join
hook in WordPress is a filter that allows modification of the SQL JOIN
clause used to combine tables in a query. WPFTS uses this hook to join the posts table (wp_posts
) with a temporary table containing post relevance information calculated by the plugin’s search engine.
What WPFTS Does When posts_join
is Called:
- Checks for Indexed Search Usage: The plugin checks if indexed search is enabled in WPFTS (
$wpq->wpftsi_session['use_indexed_search']
). - Adds JOIN with Temporary Table: If indexed search is enabled, WPFTS adds a
JOIN
with a temporary table (aliased aswpfts_t
), which contains post IDs and their relevance scores. This allows retrieving the relevance score for each post in the search results.
Important Functions Involved in posts_join
Handling:
WPFTS_Search::index_sql_joins()
How to Use This in Addon Development:
Addon developers need to be aware that WPFTS might add its own JOIN
s to the SQL query. If your addon also uses JOIN
s, ensure your logic doesn’t conflict with WPFTS.
Additional Notes:
- WPFTS only adds the
JOIN
when indexed search is used. - The temporary relevance table is created in the
WPFTS_Search::sql_parts()
method. - This hook demonstrates how WPFTS integrates its search engine with WordPress at the SQL query level.