relevanssi_join

apply_filters( 'relevanssi_join', string $query_join )

Roughly equivalent to posts_join in regular WordPress queries.

Parameters

$query_join
(string) The JOIN part of the search query.

More information

When Relevanssi constructs the database queries that are used to fetch the posts from the wp_relevanssi database table, sometimes another table needs to be JOINed to the query (in default use, using a meta_query would be such a case).

If you want to combine some extra data from another table to the Relevanssi query, you need to use this filter hook to JOIN the table and then relevanssi_where to add the actual restriction, like you would with posts_where.

However, remember you’re not querying from wp_posts, but wp_relevanssi, so do look into the database structure so you know what you’re doing. One key thing to note is that the post ID is in the wp_relevanssi.doc column, instead of wp_posts.ID.

Also remember that especially if you’re using meta queries, there may be other JOINs already in place.

add_filter( 'relevanssi_join', 'rlv_sample_join' );
function rlv_sample_join( $query_join ) {
  $query_join .= ' LEFT JOIN custom_table ct ON ct.post_id = relevanssi.doc';
  return $query_join;
}

add_filter( 'relevanssi_where', 'rlv_sample_where' );
function rlv_sample_where( $query_where ) {
  $query_where .= ' AND ct.column_value = "purple"';
  return $query_where;
}