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

Blocking pre and code tags
If your posts have lots of programming code examples in <pre> and <code> tags, those might look pretty bad in…
Popular searches
This is a very common request: “How do I show the most popular searches in a widget or on a…
How to include specific posts
Hello, I’m using WooCommerce and Relevanssi and they work great.My Site Search only searches Products, however I want to let…

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