Last active
March 27, 2020 15:10
-
-
Save bchiang7/cdc9a4f80bef713a8f00b06b2b8f442f to your computer and use it in GitHub Desktop.
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('get_algolia_index_name', 'get_algolia_index_name'); | |
// Filter to construct canonical index names | |
function get_algolia_index_name($name = '') { | |
global $wpdb; | |
$env_prefix = getenv('ALGOLIA_INDEX_PREFIX') ?: ''; // local, dev, stage, or prod | |
$base_prefix = $wpdb->base_prefix; // wp_ | |
return "${env_prefix}_${base_prefix}${name}"; | |
} | |
// When ALGOLIA_INDEX_PREFIX=local, this ends up being `local_wp_global_search` | |
$canonical_index_name = apply_filters('get_algolia_index_name', 'global_search'); | |
// Then init the `local_wp_global_search` index | |
$global_index = $algolia->initIndex($canonical_index_name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment