ACF advanced custom Fields in results description

Home Forums Product Support Forums Ajax Search Pro for WordPress Support ACF advanced custom Fields in results description

This topic contains 2 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17247
    MarkChask
    MarkChask
    Participant

    Hi.
    I would like to know if I can use advanced custom fields in the results description.

    This is an example of the field (ACF is set to return the url of a file)
    <?php the_field(‘file_download’); ?>
    Result:
    http://www.mysite…../file.pdf

    Ajax pro finds the custom field {file_download} but returns the media id.
    {file_download}
    result:
    4001

    Is there a way to get the file url instead of the file ID?

    #17248
    MarkChask
    MarkChask
    Participant

    I wrote this. Maybe if you want to share it:

    add_filter( 'asp_results', 'asp_custom_field_to_title', 1, 1 );
      
    function asp_custom_field_to_title( $results ) {
      $custom_field = "super";
     
      foreach ($results as $k=&gt;$v) {
    
          $meta_value = get_field('file_download',$results[$k]-&gt;id); // ACF support
            
          if($meta_value){
             $results[$k]-&gt;title  .= " - <a href='" . $meta_value . "' target='_blank'>Download</a>";
           }
           else{
              $results[$k]-&gt;title;
           }
      }
      
      return $results;
    }
    #17261
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thank you very much for sharing the code, I will keep it public, so others can find it as well. It is good to know that ACF file upload fields return the media ID only.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.