Automatic redirects to category with ACF taxonomy

Hi Mikko

I have relevanssi premium, and ACF taxonomies. The indexing works great and these are also taken into account during the search. I wanted to use your code to direct to the taxonomies if a search term matches exactly. I took the following code in Wpcodebox :

add_action( 'saved_term', function() {
    $redirects    = get_option( 'relevanssi_redirects', array() );
    $product_cats = get_categories( 'taxonomy=product_cat' );

    $existing_redirects = wp_list_pluck( $redirects, 'url' );
    foreach ( $product_cats as $cat ) {
        $url = get_category_link( $cat->term_id );
        if ( ! in_array( $url, $existing_redirects, true ) ) {
            $redirects[] = array(
                'url'     => $url,
                'query'   => $cat->name,
                'partial' => false,
                'hits'    => 0,

    update_option( 'relevanssi_redirects', $redirects );
} );

Then I went into a taxonomy and re-saved it, as it says in your instructions. But it doesn’t happen, I enter the taxonomy as a search term and it doesn’t redirect. do you have any idea?


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer