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 6 years, 5 months ago.
- AuthorPosts
- March 24, 2018 at 10:24 pm #17247
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.pdfAjax pro finds the custom field {file_download} but returns the media id.
{file_download}
result:
4001Is there a way to get the file url instead of the file ID?
March 24, 2018 at 11:23 pm #17248I 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=>$v) { $meta_value = get_field('file_download',$results[$k]->id); // ACF support if($meta_value){ $results[$k]->title .= " - <a href='" . $meta_value . "' target='_blank'>Download</a>"; } else{ $results[$k]->title; } } return $results; }
March 26, 2018 at 9:31 am #17261Hi!
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 :)
- AuthorPosts
You must be logged in to reply to this topic.