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

Avada
Avada is one of the most popular WordPress themes on the market. All post types are not found Avada has…

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