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

Automatic redirects to category archives

While Relevanssi Premium can return taxonomy terms as search results, sometimes sending the searcher directly to the category archive is better. This is especially true for WooCommerce sites, where displaying taxonomy terms in search results pages is complicated. Relevanssi Premium has a redirect feature you can use to redirect searches…

Yoast Local SEO
Yoast Local SEO plugin breaks Relevanssi search. It enhances the search by adding meta queries. Unfortunately they don’t work with…

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