Skip to main contentSkip to footer

ACF: Field names appearing in excerpts

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

ACF: Indexing relationship content

If your posts include content from related posts using the Advanced Custom Fields relationship functionality, Relevanssi doesn’t index that content by default. Even if you set Relevanssi up to index the ACF fields, the relationship fields do not include any content, just references to other posts. Those, even if indexed,……the field names to match the names of your fields. In this case, the relationship field is called relationship_field, the user connection field is called user_connection and the taxonomy connection field is called taxonomy_connection. Your fields name are likely different, so make sure the get_post_meta() calls reference the correct field……name. This function covers fetching post data, user data and taxonomy term data. For taxonomy terms, there’s the more complete solution that figures out the taxonomy from the field settings, but if the taxonomy is never going to change, you can skip all that and just set the taxonomy in…

WP All Import
By default posts imported with WP All Import do not get indexed by Relevanssi. The importing process does not trigger…
Search shortcode

Relevanssi adds a shortcode to help making links to search results. That way users can easily find more information about a given subject from your blog. The syntax is simple: John Doe This will make the text John Doe a link to search results for John Doe. In case you…

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