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

Category title in the search results page

If you’re using category restriction dropdown on your search form, here’s a bit of code that you can add to your search results template to show how many hits were found and what the category is. If no category was selected, this’ll just show how many hits were found. <?php…

WooCommerce: Searching for orders

Searching for shop orders is tricky with WooCommerce. WooCommerce blocks searching the orders. WooCommerce also keeps the order data in many different tables. Because of this complexity, the shop_order post type is not available for indexing. You can enable it by adding this to your site: add_filter( ‘option_relevanssi_index_post_types’, function( $post_types……$status_array; } Now the orders are available in the Relevanssi admin search. They are still excluded from the front end search. Relevanssi indexes very little information about the order by default. You only get the order date. WooCommerce stores the items in the order in wp_woocommerce_order_items. Some stats about the…

ACF: Indexing relationship content

…know the exact field name. In that case you can use a direct database call to fetch fields using wild cards. This function would find a relationship field called people inside a flexible content field sidebar_groups: add_filter( ‘relevanssi_content_to_index’, ‘rlv_relationship_content’, 10, 2 ); function rlv_relationship_content( $content, $post ) { global $wpdb;…

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