• nitintech

    (@nitintechacadiumcom)


    Hello,
    How i can use advanced custom fields values in relevanssi search. I am using following code but it’s not working.
    add_filter(‘relevanssi_excerpt_content’, ‘excerpt_function’, 10, 3);

    function excerpt_function($content, $post, $query){
    	    $relevanssi_index_post_types = relevanssi_get_custom_fields();
    	    if(!empty($relevanssi_index_post_types)){
    	        $meta_values = '';
    	        foreach($relevanssi_index_post_types AS $custom_post_type){
    	            $meta_value = get_post_meta( $post->ID, $custom_post_type, true);
    	            if(!empty($meta_value)){
    	                $meta_values .= $meta_value.' ';
    	            }
    	        }
    	    }
    
    	    if(!empty($meta_values)){
    	        $content .= preg_replace("/\n\r|\r\n|\n|\r/", " ", $meta_values);
    	    }
    
    	    return $content;
    	}

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Thanks.

    https://wordpress.org/plugins/relevanssi/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    What do you have in the “Custom fields to index” setting?

    Thread Starter nitintech

    (@nitintechacadiumcom)

    I have name, address and specialization custom fields of a custom post type. I want to search a post on the basis of these fields.

    Plugin Author Mikko Saari

    (@msaari)

    And what exactly is the problem? Can you find the posts by the custom field content or not? Since your code is about excerpts, is the problem that you find the posts, but the excerpts are wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Urgent’ is closed to new replies.