Created
February 6, 2024 10:00
-
-
Save sachyya/7562d799b58b35e2eb9e4b93741eca9b to your computer and use it in GitHub Desktop.
Typesense Customization
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 | |
function cm_typesense_format_resource_category_data ( $formatted_data, $raw_data, $object_id, $schema_name ) { | |
if ( $schema_name == 'resource' ) { | |
$terms = get_the_terms( $object_id, 'resource-category' ); | |
$resource_categories = []; | |
foreach ( $terms as $term ) { | |
// Hide the "Thank you" category. | |
// skip "Thank You" category from being indexed | |
if( $term->name != 'Thank You' ) { | |
$resource_categories[] = $term->name; | |
} | |
} | |
$formatted_data['resource-category'] = $resource_categories; | |
} | |
return $formatted_data; | |
} | |
add_filter( 'cm_typesense_data_before_entry', 'cm_typesense_format_resource_category_data', 10, 4 ); | |
// Change the headings for the facets | |
add_filter( 'cm_typesense_search_facet_title', 'your_slug_change_facet_title', 10, 3 ); | |
function your_slug_change_facet_title( $title, $filter, $post_type ) { | |
if( 'resource-category' == $filter ) { | |
$title = 'Resource Category'; | |
} | |
return $title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment