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

Custom URL link for results quit working for a Search Instance

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Custom URL link for results quit working for a Search Instance

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #55956
    Jim GillonJim Gillon
    Participant

    ajax search pro – clicking an item in the results list (from page “www.catnewstand.com/stories” and the search instance “within News – auto populate”} used to work as expected, but now does not link to the custom field url “news_url” – instead, it goes to the url of the post

    #55960
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    I assume you had a custom code in place to change the URLs, but I couldn’t find it anywhere.

    I have added the Code Snippets plugin and added the following custom code to fetch the news_url custom field:

    add_filter( 'asp_results', function ( $results, $search_id, $is_ajax, $args ) {
    	// Change this variable to whatever meta key you are using
    	$meta_key = 'news_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;
    			}
    		}
    	}
    
    	return $results;
    }, 10, 4 );
    #55963
    Jim GillonJim Gillon
    Participant

    Thank you. The provided JavaScript filter fixed the issue. I was provided with a similarly-coded filter in July of this year – and due to issues with OneDrive vs local storage, did not find the JavaScript. I will avoid that issue in the future.

    #55964
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You are welcome!

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