Plugin Contributor
Sachyya
(@sachyya-sachet)
Hello @johnwiggity
Hope you are doing well.
One simple solution is to unassign the category you want to exclude from the posts and update the posts.
Or you can use the below code in your child theme’s functions.php to exclude specific category:
<?php
function your_slug_exclude_category ( $formatted_data, $raw_data, $object_id, $schema_name ) {
if ( $schema_name == 'post' ) {
$categories = get_the_category( $raw_data->ID );
if ( ! empty( $categories ) ) {
foreach ( $categories as $category ) {
// Replace 54 with your category ID
if( 54 == $category->term_id ) {
$formatted_data['category'] = [];
}
}
}
}
return $formatted_data;
}
add_filter( 'cm_typesense_data_before_entry', 'your_slug_exclude_category', 10, 4 );
Please not you would have to index your posts again for this to take affect.
Hope this helps. Please let us know if you need further assistance.
Regards
Ok thanks so much! The plugin works great.
I had one other quick question. With the sorting, is the Recent based on recently updated posts? Is there a way to change that by post date?
Plugin Contributor
Sachyya
(@sachyya-sachet)
Hello @johnwiggity ,
Glad it is working for you.
The Recent sorting is based on post_date not on the post_modified date.
You can change it by using the filter: cm_typesense_search_sortby_settingsor override the sort-by.php template from templates/partials/sort-by.php. Read more about overriding templates here: https://docs.wptypesense.com/template-overriding/
Regards,
Ok thanks so much. The last thing I was wondering is if it’s possible to filter out any shortcodes that show up in the search results?
Plugin Contributor
Sachyya
(@sachyya-sachet)
Hello @johnwiggity ,
To exclude the shortcodes from showing up in the search results, you can do it with one of the following approaches:
1. Use the_content filter to strip out the shortcodes
2. Use cm_typesense_data_before_entry filter to filter the content before indexing it.
Hope this helps. Please get back to us if you need further assistance.
Regards