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

Modifying the search form on the fly

I set up a short coded search box to search my Learndash e-course for one specific category only: [ searchform ld_topic_category=”156″ ] It works perfectly except one thing: if no results show, it takes you to the default WordPress page and presents you with the standard search box that no……longer searches category 156. This problem isn’t generally very hard to fix. The exact solution depends somewhat on the theme. In this case the theme used was Astra, and Astra makes this very easy by using the default WordPress search form powered by get_search_form(). We want to modify the search…form. If the ld_topic_category parameter is set, the search form should include it and keep the value. That way the “No results found” page would use the same search parameter. We can’t just hardcode it, because we don’t want the search form to always use the parameter; only when the…

Italian plurals

…or “che”, the ending is changed to “ga” or “ca”, respectively. Then if the word is over three letters long, a final “a”, “e”, “i”, or “o” is stripped. Now plural and singular forms are considered the same in the search. Remember to rebuild the index after adding this function!…

Sorting search results
If you want something else than the default relevancy ranking, you can use orderby and order parameters for the search…

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