Created
May 5, 2020 14:04
-
-
Save mustardBees/23677e45ff5cae66c519a5065738fe7e to your computer and use it in GitHub Desktop.
WordPress WP Search with Algolia plugin - push custom fields to Algolia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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