Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress WP Search with Algolia plugin - push custom fields to Algolia.
<?php
/**
* Push custom fields to Algolia.
*
* @param array $attributes
* @param WP_Post $post
*
* @return array
*/
function iweb_algolia_product_attributes( array $attributes, WP_Post $post ) {
// Bail if this isn't our product post type.
if ( 'product' !== $post->post_type ) {
return $attributes;
}
$sku = get_post_meta( $post->ID, '_cmb_sku', true );
$attributes['sku'] = $sku;
return $attributes;
}
add_filter( 'algolia_post_shared_attributes', 'iweb_algolia_product_attributes', 10, 2 );
add_filter( 'algolia_searchable_post_shared_attributes', 'iweb_algolia_product_attributes', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.