• Resolved Alex Volkov

    (@vol4ikman)


    I am triying to add to index custom post type ACF fields with no success…

    Using this 2 filters:

    add_filter( 'algolia_post_shared_attributes', 'wizo_algolia_custom_fields', 10, 2 );
    add_filter( 'algolia_searchable_post_shared_attributes', 'wizo_algolia_custom_fields', 10, 2 );
    if ( 'album' !== $post->post_type ) {
    			// We only want to add an attribute for the 'speaker' post type.
    			// Here the post isn't a 'speaker', so we return the attributes unaltered.
    			return $attributes;
    	}

    Can you help with this?

    Thanks.

Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You’re definitely on the right track. Perhaps something like this though, to amend your attempt a touch.

    function wizo_algolia_custom_fields( $attributes, $post ) {
    	// Just don't even bother if not the right post type.
    	if ( 'speaker' !== $post->post_type ) {
    			return $attributes;
    	}
    
    	// Fetch our field, please fill in with actual values.
    	$fieldOne = get_field( 'my_field', $post->ID );
    	if ( $fieldOne ) {
    		// If we found a value, add.
    		$attributes['fieldOne'] = $fieldOne;
    	}
    	
    	// And return.
    	return $attributes;
    }
    add_filter( 'algolia_post_shared_attributes', 'wizo_algolia_custom_fields', 10, 2 );
    add_filter( 'algolia_searchable_post_shared_attributes', 'wizo_algolia_custom_fields', 10, 2 );
    
Viewing 1 replies (of 1 total)
  • The topic ‘Index ACF fields’ is closed to new replies.