Skip to main contentSkip to footer

Ultimate FAQs is a FAQ plugin that can create FAQs. It has a search, and enabling Relevanssi may break that search.

There are two ways to fix these problems.

Using Relevanssi

The search comes up blank because Relevanssi takes over (it’s a regular search, after all), and the ufaq post type is not indexed. Index the post type, and the search should work.

Indexing the post type causes the ufaq posts to appear in the main site search. We need to modify the search queries to exclude the ufaq post type unless it’s explicitly required.

Here’s how:

add_filter( 'relevanssi_modify_wp_query', 'rlv_no_ufaqs' );
/**
 * Excludes the Ultimate FAQs FAQ post type from the search.
 *
 * Unless the 'post_type' query variable is set to the FAQ post type, this
 * adds the FAQ post type as an excluded post type to the 'post_type'.
 *
 * @param WP_Query $query The WP_Query object.
 */
function rlv_no_ufaqs( $query ) {
	if ( EWD_UFAQ_FAQ_POST_TYPE === $query->query_vars['post_type'] ) {
		return $query;
	}
    if ( ! empty( $query->query_vars['post_type'] ) ) {
		$query->query_vars['post_type'] .= ',';
	}
    $query->query_vars['post_type'] .= '-' . EWD_UFAQ_FAQ_POST_TYPE;
	return $query;
}

Add this to your site. This function will add the FAQ post type as a negative post type unless the search is explicitly asking for the FAQ post type.

Not using Relevanssi

Another option is to block Relevanssi out of the FAQ queries. Here’s how you do that:

add_filter( 'relevanssi_prevent_default_request', 'rlv_ufaq_query', 10, 2 );
add_filter( 'relevanssi_search_ok', 'rlv_ufaq_query', 10, 2 );
/**
 * Makes Relevanssi leave Ultimate FAQ searches alone.
 *
 * On relevanssi_prevent_default_request this function makes Relevanssi not block
 * the default WP query when the post_type parameter is set to the Ultimate FAQs
 * FAQ post type. On relevanssi_search_ok this function will make Relevanssi not
 * run the search.
 *
 * @param bool     $do_stuff Should Relevanssi functions do the things they do?
 * @param WP_Query $query    The WP_Query object.
 */
function rlv_ufaq_query( $do_stuff, $query ) {
	if ( EWD_UFAQ_FAQ_POST_TYPE === $query->query_vars['post_type'] ) {
		$do_stuff = false;
	}
	return $do_stuff;
}

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Divi

…$content ); $content = preg_replace( ‘~\ ~ims’, ”, $content ); return $content; } This function will clean all the shortcodes and their contents where the label matches one of the menu labels. It’s crucial to run these filters on priority 8 or earlier because the Relevanssi code that cleans out…

Direct access to the query engine
Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some…
Partial matches to just one custom field

…different parts of the post, but you can enable partial matching and then discard partial matches for the parts where they are not wanted. To allow partial matches, but only in the custom field sku, you can do this with relevanssi_match: add_filter( ‘relevanssi_match’, ‘rlv_partial_partial’, 10, 3 ); /** * Allows……$idf The IDF value for calculating weight, not used. * @param string $term The search term. * * @return object $match The modified match object. */ function rlv_partial_partial( $match, $idf, $term ) { if ( $term !== $match->term ) { $cf_detail = json_decode( $match->customfield_detail ); if ( ! isset( $cf_detail->sku……partial matches but only in the custom field ‘sku’. * * For posts that have partial matches outside the custom field ‘sku’, * set the weight to to eliminate them from the search results. * * @param object $match The match object with the custom field detail. * @param int…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed