This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17247
    MarkChaskMarkChask
    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&#8230;../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
    MarkChaskMarkChask
    Participant

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

    [code]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;
    }[/code]

    #17261
    Ernest MarcinkoErnest 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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.