relevanssi_search_filters

apply_filters( 'relevanssi_search_filters', array $args )

This filter hook filters the Relevanssi search parameters.

Parameters

$args
(array) An array of search parameters.

More information

The parameter array has the following items that cover all the ways you can control the Relevanssi searches from the query variables:

  • admin_search (boolean): if true, this is an admin search.
  • author (int): the author ID.
  • by_date (string): date limit in the number-unit format, for example “24h“.
  • date_query (WP_Date_Query): a date query object.
  • expost (string): a comma-separated list of post ID values Relevanssi excludes from the search.
  • fields (string): the desired output format, with possible values of “ids” (only post IDs), “id=>parent” (an object with post ID and parent ID), or “id=>type” (an object with post ID and object type).
  • include_attachments (boolean): if true, Relevanssi makes sure to include the attachment post type.
  • meta_query (array): a meta query array that Relevanssi converts to a WP_Meta_Query.
  • operator (string): the search operator, “AND” or “OR“.
  • order (string): the ordering direction, “DESC” or “ASC“.
  • orderby (string, array): the ordering method, either a string or an array of (orderby, order) pairs.
  • parent_query (array): an array with two indices, one for parent post IDs whose children Relevanssi should include (“parent in“) and one for parent post IDs whose children Relevanssi excludes (“parent not in“).
  • post_query (array): an array with two indices, one for post IDs Relevanssi should include (“in“) and one for post IDs Relevanssi excludes (“not in“).
  • post_type (string, array): the post types that Relevanssi includes in the search, either a single post type, a comma-separated list, “any” or an array of post type names.
  • post_status (string, array): the post statuses that Relevanssi includes in the search, either a single post status, a comma-separated list, or an array of post statuses.
  • q (string): the search query.
  • q_no_synonyms (string): the original search query without any added synonyms.
  • sentence (boolean): if true, Relevanssi considers the search query a phrase.
  • tax_query (array): a tax query array that Relevanssi processes; for the proper format, see the WP_Query documentation.
  • tax_query_relation (string): the general default relationship between different taxonomy queries, “AND” or “OR“.

You can adjust all these parameters with this filter hook. Relevanssi will then use the modified values to build the query restrictions controlling the search queries.

The filter hook relevanssi_search_params is almost the same. Relevanssi applies that filter slightly before relevanssi_search_filters and relevanssi_search_params also gets the WP_Query object as a parameter, so if you need more context, the other hook is the better choice.

∞ Infinite loop warning

If you use this filter hook to set the operator parameter to AND, you may end up in an infinite loop when the “OR fallback” setting is enabled. Use the relevanssi_search_params instead, or disable the “OR fallback”.

Examples