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

Search is ignoring accents
In general, searches ignore accents, which is generally a good idea: for example in French, the difference between e and…
Using Relevanssi without a search term
Deprecated: Relevanssi has long supported searching without a search term. These instructions are not necessary. Version 1.7.3 introduces the possibility…

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