• Resolved VFHwebdev

    (@vfhwebdev)


    It looks like Relevansi isn’t indexing the custom fields I set up through Advanced Custom Fields.

    I’ve added the field names as a comma separated list to the “Custom Fields to Index” option field but they still don’t seem to be included in the search results.

    Is there another setting I need to check? Is there a known issue with custom fields set up through “Advanced Custom Fields”?

    Thanks

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter VFHwebdev

    (@vfhwebdev)

    A little more info. On further inspection, it looks like some of my fields are getting indexed. The ones that aren’t all appear to be “relationship” ACF fields.

    Plugin Author Mikko Saari

    (@msaari)

    How should Relevanssi index the relationship field?

    Thread Starter VFHwebdev

    (@vfhwebdev)

    At a minimum it’d be great if it could index at least the post title of related posts.

    Here’s an example use case.

    We’re running a web site for a festival. The festival has events and speakers, both of which are custom post types. There’s a relationship field that connects speakers with the events they are speaking at.

    Right now, when you search for a speaker by name, you don’t get the events at which they are speaking.

    Plugin Author Mikko Saari

    (@msaari)

    Ok, that’s definitely something you need to teach Relevanssi to do. Fortunately, somebody else has asked this before, and I have some instructions available in the KB.

    Thread Starter VFHwebdev

    (@vfhwebdev)

    Thanks! I’ll take a look and see if I can apply it to my situation. I appreciate the quick and helpful response.

    Thread Starter VFHwebdev

    (@vfhwebdev)

    I’m making progress but there are a couple of things about the example I’m having trouble understanding.

    Here’s the example for reference:

    add_filter('relevanssi_content_to_index', 'beautymed_add_product', 10, 2);
    add_filter('relevanssi_excerpt_content', 'beautymed_add_product', 10, 2);
    
    function beautymed_add_product($content, $post) {
    
        $tplName = get_post_meta( $post->ID, '_wp_page_template', true );
    
        if ($tplName === 'template-types.php') {
    
            $products = get_field('produits');
    
            foreach ($products as $product) {
                $content .= get_field('description', $product->ID);
                $content .= get_field('infos', $product->ID);
                $content .= get_field('conseils', $product->ID);
            }    
    
        }
    
        return $content;
    }

    And here’s what I’m trying to do.

    add_filter('relevanssi_content_to_index', 'bookfest_add_participant', 10, 2);
    add_filter('relevanssi_excerpt_content', 'bookfest_add_participant', 10, 2);
    
    function bookfest_add_participant($content, $post) {
    	$participants = get_field('participants', $post->ID);
    	if($participants){
    		foreach ($participants as $participant) {
    			$content .= get_the_title( $participant->ID );
    		}
    	}
        return $content;
    }

    Checking for the page template isn’t working for me. I guess my theme is using the default template. So I thought it made more sense to check for the existence of the Participants field. But this isn’t working. I tried removing the “if (participants)” condition and still no dice. Any suggestions?

    Thread Starter VFHwebdev

    (@vfhwebdev)

    I think I may have found the problem. I have more than one participant per event and I think the additions to $content need a space between them.

    add_filter('relevanssi_content_to_index', 'bookfest_add_participant', 10, 2);
    add_filter('relevanssi_excerpt_content', 'bookfest_add_participant', 10, 2);
    
    function bookfest_add_participant($content, $post) {
    	$participants = get_field('participants', $post->ID);
    	if($participants){
    		foreach ($participants as $participant) {
    			$content .= get_the_title( $participant->ID );
                            $content .= " ";
    		}
    	}
        return $content;
    }
    Plugin Author Mikko Saari

    (@msaari)

    Yes, adding spaces between the entries is a good idea.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Indexing ACF fields’ is closed to new replies.