I am using a custom post type which is being indexed properly, but I need to also search for keywords within my custom taxonomies (for ex. I have a custom taxonomy called “Project Tags” which behaves similarly to normal tags but is only for tags on my custom post type “Project”).
Is there a way to get Swiftype to index custom taxonomies?
This can be accomplished by adding the following code to your WordPress theme’s functions.php
and then resynchronizing the Swiftype plug-in.
function swiftype_search_params_filter($params) {
$params['search_fields[posts]'] = array('terms^10', 'title^1');
return $params;
}
add_filter('swiftype_search_params', 'swiftype_search_params_filter');
function swiftype_document_builder_filter($document, $post) {
$term_names = array();
$taxonomy_names = get_object_taxonomies($post);
foreach($taxonomy_names as $taxonomy) {
$terms = get_the_terms($post - > ID, $taxonomy);
if (is_array($terms)) {
foreach($terms as $term) {
array_push($term_names, $term - > name);
}
}
}
$document['fields'][] = array('name' => 'terms', 'type' => 'string', 'value' => $term_names);
return $document;
}
add_filter('swiftype_document_builder', 'swiftype_document_builder_filter', 8, 2);
If your WordPress theme is heavily customized, it might require some additional modifications, but you should find it compatible with Swiftype Plug-in versions 1.1.34 or higher.