posts_where Hook in WPFTS

The posts_where filter in WordPress allows modification of the SQL WHERE clause used for post selection. WPFTS utilizes this hook to add MIME-type-related conditions when searching attachments.

What WPFTS does when posts_where is called:

  1. Indexed Search Check: The plugin checks if indexed search is enabled in WPFTS ($wpq->wpftsi_session['use_indexed_search']).

  2. Adding MIME-Type Conditions: If indexed search is enabled, WPFTS analyzes the wpfts_temp_mimes query parameter, which contains a list of MIME types to search for. The plugin adds a condition to the WHERE clause that restricts the selection to posts with the specified MIME types. This allows searching only for specific file types (e.g., PDF, DOCX).

Important Functions Involved in posts_where Handling:

  • WPFTS_Search::index_sql_where()

  • WPFTS_Search::wpfts_wp_post_mime_type_where() (helper function for generating the WHERE condition for MIME types)

How to Use This in Addon Development:

Addon developers should be aware that WPFTS modifies the WHERE clause to handle MIME types. If your addon also adds conditions to the WHERE clause, ensure your logic doesn’t conflict with WPFTS.

Additional Notes:

  • WPFTS adds MIME-type conditions only if indexed search is used.

  • The wpfts_temp_mimes parameter is used for temporary storage of MIME types, as the standard post_mime_type parameter is cleared by the plugin in the WPFTS_Search::index_pre_get_posts() method.

  • The wpfts_wp_post_mime_type_where function is used to generate the correct WHERE condition for MIME types, taking wildcards into account.

This hook demonstrates how WPFTS handles MIME-type searching and can be useful for addon developers integrating with file searching.