Hi Tainacan Community!
We set up Tainacan on the Salient theme and have been populating the site (about 150 items now). Our goal is to use the default WordPress search functionality (see search icon located on the top right hand side of the header) to allow users to find the Tainacan posts, currently this is not working out of the box:
Is there any documentation available on how to achieve this?
Thanks!
Jes
Hi @jpdstudio!
The site is shaping really nice! We do have some documentation about how to make themes compatible with Tainacan. However, their focus is mainly on two things:
- Making the items archive display the whole faceted search (the list with filters that you see in the admin);
- Making the item single page display all of their info (attachments, media gallery with zoom, metadata sections, etc).
The second topic is about to become a bit deprecated from the release that we are putting out today. It should do this automatically for every theme . The first one is still necessary if you want to have the items list with Filters and Advanced search available on the theme side, instead of a simples “post-like” list of items. I can help you with that part if the documentation mentioned above is not enough.
None of this actually covers the topic that you just mentioned, which implies making the WordPress default search to look for Tainacan items. You can do that by enabling the search in our Custom Post Types. Every collection that you create in Tainacan is a new “Post Type” and every item a post of that type. WordPress default search looks for posts and pages.
It is possible that this can be enabled via some settings of your theme, I’m just not familiar with it. In another theme that we’ve been using, Blocksy, this is right in the Search settings section. If you cannot find a visual way to do it, you can still try to add them via code. There are numerous tutorials about this, but looking at this one, what you are looking for would be something like this:
<?php
function my_custom_search_filter($query) {
if ($query->is_main_query() && $query->is_search() && ! is_admin() && defined ('TAINACAN_VERSION')) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$default_post_types = [ 'post', 'page'];
$query->set('post_type', array_merge($default_post_types, $collections_post_types) );
}
}
add_action('pre_get_posts', 'my_custom_search_filter');
?>
Please let me know if that works or if you need any other help integrating Tainacan to your theme
1 curtida
Thank you @mateus.m.luna for this very detailed and helpful overview! Glad you are liking the site progress.
An update: we have upgraded the Tainacan plugin to the latest version and have added the SearchWP plugin to expand the site’s search functionality to include Custom posts.
When we search for a musician on the site, for example “bobby”, the search Results page tells us that there are 3 posts available but it doesn’t show us the posts. Have you seen this happen before? Do you think we need to add custom code to the theme’s search template to make the Tainacan posts viewable?
Here is the sample “bobby” search for reference:
https://tinyurl.com/3wrvzsku
Please let me know if you have any insights that I can pass on to my development team. Also if your team or if you know of anyone here on discourse that specializes in customizing your plugin please let me know, we would love to work with someone on an on-going basis.
Thank you!
Jes
Uhm, that is weird… My first guess would be that these items or their collection are set as private, which would still be strange as the total count there should not appear. Can you tell us which SearchWP plugin is this? I found one but as it is payed I cannot debug it here.
Also, can you share with me a screen of the page where this step of “including Custom post” happened so I can make sure things are correct?
If none of our investigations here work out, I would suggest your development team to try the code snippet that I pasted above, it usually does the trick for themes where the search on custom post types is not enabled.
There are others that can show around, but mostly me and @vnmedeiros have been working on the plugin development and support to integrations like this, we can talk more if you have other demands
2 curtidas
Hi @mateus.m.luna! Thank you so much for your thoughtful responses. We’ve tried your suggestions but unfortunately haven’t been able to resolve the search issue. Are others having this issue? Please see my responses in bold below.
Uhm, that is weird… My first guess would be that these items or their collection are set as private, which would still be strange as the total count there should not appear. Can you tell us which SearchWP plugin is this? I found one but as it is payed I cannot debug it here.
The collections are all set to public. I can share one of my licenses/seats for SearchWP if that helps , we’re using the latest version which is 4.2.8.
Also, can you share with me a screen of the page where this step of “including Custom post” happened so I can make sure things are correct?
Sure thing, here goes:
If none of our investigations here work out, I would suggest your development team to try the code snippet that I pasted above, it usually does the trick for themes where the search on custom post types is not enabled.
This doesn’t seem to be needed since we have enabled serach on custom post stypes via the SearchWP plugin.
There are others that can show around, but mostly me and @vnmedeiros have been working on the plugin development and support to integrations like this, we can talk more if you have other demands
Yes, please let’s talk more! Please let me know what next steps are and if this is something you would be able to support us with soon. Thank you!
Uhmm I feel like we’ll have to take a look at the SearchWP plugin then. This is actually quite unusual, we’ve never had issues with search engines like that, at least not any that couldn’t be solved in a simple CTP setting as the one that you just shared.
Could you share me this license that you mentioned? I’ll open a private conversation here in the discourse.