How to change the results URL to something else?

What is this, and where do I put this custom code?

Replacing with a static URL

// Remove the line below, if you don't want to affect the Live results list
add_filter( 'asp_results', 'asp_custom_link_results', 10, 4 );
// Remove the line below, if you don't want to affect the results page
add_filter( 'asp_noajax_results', 'asp_custom_link_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
    // Replaces each result URL with this
    $replace_with = 'https://google.com';

    // --- DO NOT CHANGE ANYTHING BELOW ---
    foreach ($results as $k=>&$r) {
		// Ajax results link
		if ( isset($r->link) ) {
            $r->link = $replace_with;
        }
		// Results page link
		if ( isset($r->asp_guid) ) {
            $r->asp_guid = $replace_with;
        }
    }

    return $results;
}

Replacing multiple different URLs within the results

Enter the values to the $replace variable on line 7. On each line, the left side is the value to replace, with the value on the right side.

// Remove the line below, if you don't want to affect the Live results list
add_filter( 'asp_results', 'asp_custom_link_results', 10, 4 );
// Remove the line below, if you don't want to affect the results page
add_filter( 'asp_noajax_results', 'asp_custom_link_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $is_ajax, $args  ) {
	// Array of original -> replacement links
	$replace = array(
		'websiteurl1.com' => 'google.com',
		'websiteurl2.com' => 'wikipedia.com',
		'websiteurl3.com' => 'bing.com'
	);

	// --- DO NOT CHANGE ANYTHING BELOW ---
	foreach ($results as $k=>&$r) {
		$link = isset($r->link) ? $r->link : (isset($r->asp_guid) ? $r->asp_guid : '');
		if ( $link == '' )
		    continue;
		$link = str_replace(array_keys($replace), array_values($replace), $link);

		// Ajax results link
		if ( isset($r->link) ) {
            $r->link = $link;
        }
		// Results page link
		if ( isset($r->asp_guid) ) {
            $r->asp_guid = $link;
        }
	}

  return $results;
}

Parsing the url from post meta

What is this, and where do I put this custom code?

// Remove the line below, if you don't want to affect the Live results list
add_filter( 'asp_results', 'asp_custom_link_meta_results', 10, 4 );
// Remove the line below, if you don't want to affect the results page
add_filter( 'asp_noajax_results', 'asp_custom_link_meta_results', 10, 4 );
function asp_custom_link_meta_results( $results, $search_id, $is_ajax, $args ) {
    // Change this variable to whatever meta key you are using
    $meta_key = 'custom_url';

    // --- DO NOT CHANGE ANYTHING BELOW ---
    foreach ($results as $k=>&$r) {
        if ( function_exists('get_field') )
            $new_url = get_field( $meta_key, $r->id, true ); // ACF support
        else
            $new_url = get_post_meta( $r->id, $meta_key, true );

        // Change only, if the meta is specified
        if ( !empty($new_url) ) {
            // Ajax results link
            if ( isset($r->link) ) {
                $r->link = $new_url;
            }
            // Results page link
            if ( isset($r->asp_guid) ) {
                $r->asp_guid = $new_url;
            }
        }
    }

    return $results;
}

Last updated