This file contains hidden or 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 | |
// Inject instantsearch.js on every page regardless of backend config. | |
add_filter( 'algolia_wc_should_display_instantsearch', '__return_true' ); | |
// This will make sure the search is displayed on load. Oterwise it waits for the query to change to be displayed. | |
add_filter( 'algolia_config', function( array $config ) { | |
$config['woocommerce']['replace_page'] = true; | |
This file contains hidden or 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 | |
add_filter( 'algolia_wc_attributes_for_faceting', function( $attributes ) { | |
$only_ids = array( | |
15, // Main Style | |
13, // Main Color | |
49, // Sizes | |
23, // Brand | |
4, // Collection | |
22, // Material |
This file contains hidden or 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 | |
// See: https://github.com/algolia/algoliasearch-wordpress/blob/master/includes/class-algolia-plugin.php#L181 | |
// To be added to the functions.php of your active theme for example. | |
add_filter( 'algolia_searchable_post_types', function( array $post_types ) { | |
$post_types[] = 'my_custom_post_type'; | |
return $post_types; | |
} ); |
This file contains hidden or 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 | |
add_filter( 'algolia_wc_should_display_instantsearch', function( $should_display ) { | |
// If configuration already considers it should be shawn, show it. | |
if ( $should_display ) { | |
return true; | |
} | |
// Detect the current page and only return true when you want instantsearch.js to be injected. | |
if ( is_shop() ) { |
This file contains hidden or 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 | |
/** | |
* Plugin Name: Customize data pushed to Algolia. | |
*/ | |
/** | |
* @param int $user_id | |
* @param string $fallback_avatar_url | |
* | |
* @return string |
This file contains hidden or 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 | |
add_filter( 'algolia_autocomplete_config', function ( $config ) { | |
// echo '<pre>'; | |
// var_dump( $config ); | |
// echo '</pre>'; | |
foreach ( $config as &$index ) { | |
// Adjust and adapt according to your needs. | |
if ( $index['index_id'] === 'posts_post' ) { |
This file contains hidden or 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
<!-- ... --> | |
<script type="text/html" id="tmpl-autocomplete-zendesk-suggestion"> | |
<a class="suggestion-link" href="https://algolia-test.zendesk.com/hc/{{ data.locale.locale }}/articles/{{ data.id }}"> | |
<div class="suggestion-post-attributes"> | |
<span class="suggestion-post-title">{{{ data._highlightResult.title.value }}}</span> | |
<# if ( data._snippetResult['body_safe'] ) { #> | |
<span class="suggestion-post-content">{{{ data._snippetResult['body_safe'].value }}}</span> | |
<# } #> | |
</div> | |
</a> |
This file contains hidden or 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 | |
function add_geoloc_to_profiles($attributes) { | |
$attributes['_geoloc']['lat'] = 0; | |
$attributes['_geoloc']['lng'] = 0; | |
return $attributes; | |
} | |
add_filter('algolia_post_profiles_shared_attributes', 'add_geoloc_to_profiles'); |
This file contains hidden or 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
// using no query parameters will clear the index | |
index.deleteBy({ | |
// any browse-compatible search parameters | |
}, function(err) { | |
if (!err) { | |
console.log('success'); | |
} | |
}); |
This file contains hidden or 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 | |
$algolia = Algolia_Plugin::get_instance(); | |
$index = $algolia->get_index('posts_product'); | |
$total_pages = $index->get_re_index_max_num_pages(); | |
if ( $total_pages === 0 ) { | |
$index->re_index( 1 ); | |
return; | |
} | |
$page = 1; |