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

Reply To: Use ACF as permalink for result tile link

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Use ACF as permalink for result tile link Reply To: Use ACF as permalink for result tile link

#31041
pbpyrojust18pbpyrojust18
Participant

I just edited the ASL code for ASP and it seems to work

add_filter( 'asp_results', 'asp_custom_link_meta_results', 10, 1 );
function asp_custom_link_meta_results( $results ) {
    // Change this variable to whatever meta key you are using
    $key = 'url_to_asset';

    // Parse through each result item
    foreach ($results as $k=>$v) {
        if ( function_exists('get_field') )
            $new_url = get_field( $key, $v->id, true ); // ACF support
        else
            $new_url = get_post_meta( $v->id, $key, true );

        // Change only, if the meta is specified
        if ( !empty($new_url) ) {
            $results[$k]->link = $new_url;
        }
    }

    return $results;
}

Unless there is an updated snippet for ASP?