Skip to main contentSkip to footer

Relevanssi category exclusion setting doesn’t work properly with WPML. Here’s a bit of code from Srdjan Jocić from OnTheGoSystems that fixes it. Just add this to your theme functions.php.

add_filter( 'relevanssi_search_filters', 'wpml_relevanssi_include_exclude_cats_fix' );
function wpml_relevanssi_include_exclude_cats_fix( $args ) {
    if ( array_key_exists( 'tax_query', $args ) && did_action( 'wpml_loaded' ) ) {
        foreach ( $args['tax_query'] as &$query ) {
            if ( isset( $query['terms'] ) && isset( $query['taxonomy'] ) ) {
                $terms = null;

                if ( is_string( $query['terms'] ) ) {
                    $terms = explode( ',', $query['terms'] );
                } elseif ( is_array( $query['terms'] ) ) {
                    $terms = $query['terms'];
                }

                if ( $terms ) {
                    foreach ( $terms as &$term_id ) {
                        $term_id = apply_filters( 'wpml_object_id', $term_id, $query['taxonomy'] );
                    }
                    $query['terms'] = $terms;
                }
            }
        }
    }

    return $args;
}

Your account

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

Search

Popular Resources

Related searches feature
John Blackbourn wrote a cool related searches feature for Relevanssi Premium. It’s included from version 1.7.4. In order to use…
Using Relevanssi without a search term
Deprecated: Relevanssi has long supported searching without a search term. These instructions are not necessary. Version 1.7.3 introduces the possibility…

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