The posts_search Hook in WPFTS

The posts_search hook in WordPress is a filter that allows modification of the SQL WHERE clause responsible for searching posts by keywords. WPFTS uses this hook to replace the standard WordPress search with its own search mechanism when necessary, according to the settings.

What WPFTS Does When posts_search is Called:

  1. Checking Indexed Search Usage: The plugin checks if WPFTS indexed search is enabled for the current query ($wpq->wpftsi_session['use_indexed_search']).

  2. Replacing the WHERE Clause: If indexed search is enabled, WPFTS completely replaces the standard WordPress-generated WHERE clause with its own, which uses data from the search index. If the parameter $wpq->wpftsi_session['parts']['select'] is not empty, it will be used as the search condition.

Important Functions Involved in posts_search Handling:

  • WPFTS_Search::index_sql_select()

How to Use This in Addon Development:

Addon developers who want to integrate with WPFTS search should understand that the standard WordPress search will be completely replaced if indexed search is enabled. If your addon modifies the WHERE clause of the search query, ensure it works correctly in conjunction with WPFTS.

Additional Notes:

  • WPFTS replaces the standard search only if it is not disabled in the plugin settings or via query parameters.

  • The SQL query used by WPFTS for searching is generated in the WPFTS_Search::sql_parts() method.

This hook demonstrates how WPFTS integrates its search engine with WordPress, replacing the standard search with its own.