Closed samfrank closed 2 years ago
I have worked it out, but will write what I found out below if anyone else has the same issue.
The attachment is not index by the plugin because it does not satisfy the if statement in class-algolia-searchable-posts-index.php
in the function below:
private function should_index_post( WP_Post $post ) {
$should_index = 'publish' === $post->post_status && empty( $post->post_password );
return (bool) apply_filters( 'algolia_should_index_searchable_post', $should_index, $post );
}
Easy fix was to add the filter algolia_searchable_post_types
in your functions file then redeclare if it should be indexed or not.
function shouldIndexPostTypes($should_index, \WP_Post $post) {
$should_index = 'publish' === $post->post_status && empty( $post->post_password ) || 'attachment' === $post->post_type;
return $should_index;
}
I have one index, that contains all of my post types that I would like to be indexed and then using the Facet to filtering depeding on the post type. Keeping everything is one index make everything a lot easier for me when implementing the search on the front-end.
I am utilising the
algolia_searchable_post_shared_attributes
to then assign a different function to the post type which easily allows me to assign custom attributes to the$attrs
. Both functions below.I have a request, where the clients would like to index all the PDFs that have been uploaded to the site. However, it seems that the
algolia_searchable_post_shared_attributes
does not loop over the attachments post type?I have printed the output of the filter of
algolia_searchable_post_types
and I can clearly see the the attachment is in the outputted array?I have looked into the where the
apply_filters( 'algolia_post_' . $post->post_type . '_shared_attributes', $shared_attributes, $post )
is being called in the plugin and I can see it has an if statement which is looking to see if it is an attachment. This is at line 262 atclass-algolia-posts-index.php
.So I am confused on when the
algolia_post_shared_attributes
oralgolia_searchable_post_shared_attributes
does not index the attachments as well?Expected behavior I would like the filters of
algolia_post_shared_attributes
oralgolia_searchable_post_shared_attributes
to index attachments in the same index.Additional context I have added the additional filter of
algolia_searchable_post_attachment_shared_attributes
to call the samepostSharedAttributes
, however the attachment does not get indexed.