Skip to main contentSkip to footer

I use the ACF field type File for a download section, but the displayed file title is not indexing. The format I return the ACF field data is “File Array (array)”.

For Relevanssi, it doesn’t matter which ACF return format you choose. Relevanssi doesn’t use get_field() but instead uses the plain get_post_meta(). That always returns the post ID for File fields. To index the file title, you need to explain what you want using the relevanssi_custom_field_value filter hook. If you wish to the file title, this does the trick:

add_filter( 'relevanssi_custom_field_value', 'rlv_file_name', 10, 2 );
function rlv_file_name( $values, $field ) {
  if ( 'download_section' === $field ) {
    $values = array_map(
      function( $attachment_id ) {
        return get_the_title( $attachment_id );
      },
      $values
    );
  }
  return $values;
}

Assuming the field name is download_section, this indexes the attachment title.

Your account

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

Search

Popular Resources

WooCommerce 4.4 problems
Updating WooCommerce to version 4.4 breaks Relevanssi searches. After updating WooCommerce to version 4.4, Relevanssi searches no longer find results.…
Issues with post order plugins
If you’re getting low-quality results and the weight settings are not affecting the results, the first thing to check is…

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