Hooks and filters
SearchSync's hooks are named tangible_searchsync_*. Many also have an older tgbl_alg_* or tgbl_ss_* name; where both exist, the old name runs first and the new one runs on its result, so the new name has the final say. Use the new names in new code.
Indexing
| Filter | Arguments | Use it to |
|---|---|---|
tangible_searchsync_alter_record | $record, $post, $index_name | Add, change or remove fields on a record before it's saved |
tangible_searchsync_should_index_post | $should_index, $post, $index_name | Keep individual posts out of an index |
tangible_searchsync_posts_to_index | $posts | Change the list of posts a reindex processes |
tangible_searchsync_posts_to_index_query_args | $query_args, $content_types, $args | Change the query a reindex uses to find posts |
tangible_searchsync_reindex_on_term_edit | $should_reindex, $taxonomy | Stop term edits reindexing their posts, per taxonomy |
tangible_searchsync_default_index_attributes | $rows | Change the attributes new indexes start with |
tangible_searchsync_index_languages | $languages (code → name) | Add languages to the Index Language setting |
tangible_searchsync_indexed_content_max_bytes | $bytes | Change the 6,000-byte limit on post content. Return 0 for no limit |
tangible_searchsync_indexed_content | $text, $raw, $post | Change the post content that's indexed |
tangible_searchsync_author_avatar_args | $args, $user_id | Change the indexed author avatar (default 96px). Reindex afterwards |
tangible_searchsync_index_settings_payload | $payload, $index_settings | Change the settings pushed to the backend |
For example, to keep password-protected posts out of every index:
add_filter( 'tangible_searchsync_should_index_post', function ( $should_index, $post ) {
return $should_index && $post->post_password === '';
}, 10, 2 );
Access control
Access control is off until you switch it on for an index. Return the attribute that holds each record's access claims, such as ld_group_ids for LearnDash groups:
add_filter( 'tangible_searchsync_access_attribute', function ( $attribute, $index ) {
return $index === 'courses_index' ? 'ld_group_ids' : $attribute;
}, 10, 2 );
Records without any claims are marked public when they're indexed, so reindex after turning this on. The Local backend uses tangible_searchsync_local_access_attribute in the same way.
Backends and providers
| Filter | Use it to |
|---|---|
tangible_searchsync_register_backend | Choose the active backend by id. See Custom backends |
tangible_searchsync_register_provider | Register a personalisation provider |
tangible_searchsync_local_relevance_cap | Change how many top results the Local backend sorts within (default 1,000) |
Display
| Hook | Use it to |
|---|---|
tangible_searchsync_user_state_labels | Rename status labels such as "Enrolled" and "In progress" |
tangible_searchsync_virtual_datapoints | Add or change the per-visitor card datapoints |
tgbl_ss_card_template_content | Change a card template's HTML before it's used |
tgbl_ss_before_global_search (action) | Output content before the search override results |
tgbl_ss_after_global_search (action) | Output content after the search override results |
tangible_searchsync_log_file | Change where the debug log is written |
JavaScript filters
These use wp.hooks.
| Filter | Arguments | Use it to |
|---|---|---|
tangible_searchsync_hit_template | template, { hit, html, component, widget } | Replace a result card's markup completely |
searchsync.filters.preselect | Change a filter's preselected values |
Browser globals
| Name | What it is |
|---|---|
window.tangibleSearchsyncInstances | The InstantSearch instances on the page |
searchsyncInstanceCreated | A CustomEvent fired on window when an instance is created |