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

Adding extra boost for exact title matches

appearances in post content if ( stristr( $post->post_content, $query ) !== false ) { $results[ $post_id ] = $weight * 100; } // Boost exact matches in a custom field if ( get_post_meta( $post_id, ‘_sku’, true ) === $query ) { $results[ $post_id ] = $weight * 100; } }……can use this code to give a boost for exact matches in titles and post content: add_filter( ‘relevanssi_results’, ‘rlv_exact_boost’ ); function rlv_exact_boost( $results ) { $query = strtolower( get_search_query() ); foreach ( $results as $post_id => $weight ) { $post = relevanssi_get_post( $post_id ); // Boost cases where query appears…

Indexing and searching PDFs in WordPress

…service on a separate server. Which PDF files can you index? Since Relevanssi is a WordPress search, Relevanssi operates on WordPress posts (including all the different post types). So, to have Relevanssi index your PDFs, they need to be WordPress posts. That’s fortunately really simple: upload your PDF files to…

Ajax Load More

…of the extension, you can make Ajax Load More use Relevanssi by adding this function to your site: add_filter( ‘alm_modify_query_args’, function( $args ) { $args[‘relevanssi’] = true; return $args; } ); This function enables Relevanssi in the Ajax Load More queries. Every time Ajax Load More loads more results, it…Ajax Load More is an infinite scrolling plugin for WordPress. It has a Relevanssi extension, but with the current versions of Ajax Load More (5.5.4.1 as I write this), the extension no longer does anything. The extension relies on a filter hook that does not exist in the plugin. Instead……counts as a new search for Relevanssi logs. If you don’t like that, you can make Relevanssi only log the first Ajax Load More search. If you want that, use these functions instead of the one above: add_filter( ‘alm_modify_query_args’, function( $args ) { global $rlv_is_offset_query; $args[‘relevanssi’] = true; if (…

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