Skip to main contentSkip to footer

With Advanced Custom Fields, sometimes Relevanssi picks up custom field names to include in the excerpts.

This problem happens when you set Relevanssi to index all visible custom fields and have Flexible Content fields. Let’s assume there’s a Flexible Content field with the name flexible_content. It has a layout named field_layout, and in that layout, there are fields with the name flexible_field.

In this case, the content is in the custom field flexible_content_0_flexible_field (with increasing numbers for each new field). ACF, however, also creates a field flexible_content, which has an array with the layouts listed (at least that’s what I think it has). Since that too is a visible field, Relevanssi indexes it and uses it for excerpts. Thus the layout names appear in excerpts.

The solution to this problem is to remove the root field, flexible_content, from the Relevanssi index and excerpts. That is a straightforward thing to do with a filter function:

add_filter( 'relevanssi_index_custom_fields', 'rlv_remove_unwanted' );
function rlv_remove_unwanted( $fields ) {
    $unwanted_fields[] = 'flexible_content';
    return array_diff( $fields, $unwanted_fields );
}

Add this function to your site and rebuild the index. Now the root field is no longer indexed or used in excerpts.

Another approach is to stop using “Visible” in the custom field indexing settings and instead specify the exact fields you want Relevanssi to index. Still, with lots of Flexible Content, that can be complicated.

Your account

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

Search

Popular Resources

Modernize

…HTML tags, so Modernize may cut the excerpt in the middle of a HTML tag inserted by Relevanssi, causing the markup to break. Add this code to the theme functions.php to make highlighting work in Modernize: add_filter(‘pre_option_’.THEME_SHORT_NAME.’_search_archive_num_excerpt’, ‘relevanssi_modernize_fix’); function relevanssi_modernize_fix($value) { if (is_search()) return 1000; return $value; } This makes…Modernize is a neat Premium theme that has a problem with Relevanssi. Relevanssi highlighting can cause problems on Modernize search results pages, with results getting wrong background color. This problem is caused by the way Modernize truncates excerpts to certain length, set in the Modernize settings. It doesn’t care about…

Unyson
Unyson is a free drag & drop framework. It stores the content in a custom field fw:opt:ext:pb:page-builder:json. While Relevanssi can…
PostX Pro
If you use PostX Pro to build a search results template using their Post Grid block, you’ll notice that the…

Related Posts:

Comment Section:

4 Comments. Leave new

  • Is it possible to use this filter function on specific fields inside the Flexible Content fields?

    Reply
    • Yes, you can use this for any custom fields.

      Reply
      • steve combes
        May 30, 2022 5:44 am

        To use this filter function on a sub field, or a field nested inside a Flexible Content field, what might the $unwanted_fields line item look like to target the sub field, or field nested in Flexible Content?

        Reply
        • The best way to find out is to look at the wp_postmeta database table. You can find the names of the fields that contain the field layouts. But if you have “flexible_content_1_sub_field”, the layout is in “flexible_content”. Based on that, if you have “flexible_content_1_flexible_sub_content_1_sub_field”, you probably need to include “flexible_content_1_flexible_sub_content”. But check the database table, that’s the best way to find out.

          Reply

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