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

Relevanssi indexes excluded posts

…easy: just add the shortcode to the list of disabled shortcodes. Problem solved! This is easy to do in Relevanssi Premium where the list of disabled shortcodes is a simple setting field on the indexing settings page. With the free version, you can adjust this with the relevanssi_disabled_shortcodes filter hook….…was showing posts from the publication post type, even though that post type was excluded from the index. The reason was a shortcode, publication_archive, that was used on a page to display an archive of publications. The shortcode function fetched the posts with WP_Queryand changed the global $post object. That……theme search is not using Relevanssi for some reason. Common causes for indexing the wrong post types The most common reason for index including the wrong post type is a shortcode or some other feature that displays posts and confuses Relevanssi. In the case that prompted this post, the search…

Polylang attachment searching
If Polylang is in use and you haven’t enabled “Media translation“, your attachment files won’t have a language. That’s fine,…

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