Hi, I need to make the output of the views searchable by the plugin Relevanssi. The author of the plugin gave me this answer:
--- START OF REPLY FROM RELEVANSSI ---
Indexing query elements is tricky and may cause problems with Relevanssi. I also don't know if Toolset Views are something Relevanssi can see in the first place; I don't know Toolset well enough to tell. You can create a filter function with the relevanssi_content_to_index hook for adding extra information to any page. Here is an example:
add_filter( 'relevanssi_content_to_index', 'rlv_add_extra_content', 10, 2 );
function rlv_add_extra_content( $content, $post ) {
global $wpdb;
$content .= ' ' . $wpdb->get_var( "SELECT data FROM extra_table WHERE post_id = $post->ID" );
return $content;
}
Unfortunately, I can't help with the details, as I don't have the faintest clue of what Toolset Views are. Can you please ask the Toolset support about that? If they can tell you how to get the content from the Toolset View from the post ID, I can then help you come up with the Relevanssi filter to add the content to the posts for Relevanssi.
--- END OF REPLY FROM RELEVANSSI ---
Can you please tell me how to get View's content?
Thanks,
Nicola
Hi Nicola,
Thank you for contacting us and I'd be happy to assist.
I'm not sure if I understand the requirements clearly. In general, Relevanssi extends the WordPress default text search feature, which Toolset views also support, to enhance the indexing criteria.
( ref: https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/ )
The output from Toolset views is just a way to display the post data, that is already saved in the database. This data is also already indexed by Relevanssi, as it is not dependant on what is rendered on the front-end pages, but, reads it directly from the database.
So, I can't think of a use case, where you'd need to specifically make the output of the views searchable by Relevanssi.
I hope this explanation helps and please let me know if I'm missing something.
regards,
Waqar
Hi Waqar, thank you for your reply.
I'll make an example to better explain my issue:
I have a page called "Cardiology" (custom post type "Services") where I am filtering with Toolset Views the physicians based on their taxonomy (physicians are inserted using the custom post type "Doctors"). Suppose I have a cardiologist named "John Smith" who is shown, thanks to a view, on the page "Cardiology". Now, if I try to search for the word "smith", in the results I get the page "John Smith" but not the page "Cardiology".
I looked at the link you posted to me and I've found nothing wrong in my settings.
Do you have other suggestions?
Thanks,
Nicola
Hi, I forwarded your response to the Relevanssi developer who told me to ask you the following:
---
My custom posts are profiles of physicians. I know Relevanssi can index the individual custom posts; it does that. I use a view to display these physicians on pages about their branches. For example, the cardiology page has a list of cardiologists. These views are invisible to Relevanssi: on the cardiology page, Relevanssi only sees the introductory text, not the list of cardiologists generated from the view. I would like to have Relevanssi index this view so when people search the names of the cardiologist, they find the cardiology branch page.
How would I do that? Relevanssi doesn't need to have the rendered view; just a method of figuring out the post IDs of the posts linked to the view on the branch page would be enough. Is there a function I could use to get either the rendered view or a list of the post IDs based on the branch page ID?
---
I Hope things are more clear now, thanks
Nicola
Hi, do you have any update about my request?
Thanks,
Nicola
Thank you for sharing these details.
I've performed some tests on my website with Relevanssi and views and it seems what you're looking for is already supported.
I created some test views (using the classic editor as well as the blocks editor) that showed the titles of posts from a post type. Then I included those views as the content on pages, through views shortcodes as well as through the views block.
Next, I made sure that the option "Expand shortcodes when indexing" was checked in Relevanssi's "Indexing" settings and used the "Build the index" option.
After that, when I used the text search on the website, to look for some of the words that were included in the post titles covered in the views, the pages which contained those views also showed up in the search results. This confirms that Relevanssi was able to find those post title text in the pages with the views.
Can you please use the same steps to test this and let me know how it goes?
Hi Waqar,
I double checked the steps you indicated but the website was already set up correctly. If you go to the page hidden link (username "pavanello" and password "riviera" to view the page), you can see a list of red rows, these are the services printed by a view.
The first one is "Eco color doppler cardiaco" and, if you try to search the phrase "eco color doppler cardiaco" the page "Cardiologia" should appear in the results, instead it is showing only the page of the service. See uploaded image for more details.
If you need I can give you admin access to the website.
Cheers,
Nicola
Thank you for waiting as we were a little light on the coverage, due to the holidays.
It looks like something specific to this website or page(s) is involved. Can you please share temporary admin login details, in reply to this message for further troubleshooting?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
Thank you for sharing these details.
I've checked your website's pages section and couldn't find any page named "Cardiologia".
( screenshot: hidden link )
The link that you mentioned ( hidden link ) is for a single "Branche" post. It does have the text "eco color doppler cardiaco" coming from the view's output. When the search is performed for the text "eco color doppler cardiaco" this single "Branche" post is showing in the search results.
( screenshot: hidden link )
Can you please share any other example, where the page with the view's output is not getting included in the search results?
Hi Waqar,
I'll try to explain better the issue (the numbered lines are showing your text, my comments are below).
1. The link that you mentioned ( hidden link ) is for a single "Branche" post.
Yes, this is an example of post that has the issue (sorry if I confused you, sometimes I use the word "page" even when I'm referring to custom post types content, as in this case).
2. When the search is performed for the text "eco color doppler cardiaco" this single "Branche" post is showing in the search results.
No, what you see in the search results is the "eco color doppler cardiaco" post. Actually it is linking to the post "Cardiologia" but just because I customized the search view to make it print a custom link: instead of using the post URL I print the URL of the Branca (Branch) post that shares the same taxonomy. Consider it a temporary loophole, we would like to get explicitly the post "cardiologia" when a user makes this search.
To make another example, in the same post "Cardiologia" there is the name of the doctor "Umberto Calvello". If you search for the word "Calvello" you get only the post of the doctor, but we expect to get also the post "Cardiologia", since it contains this word. Keep in mind, however, that this is actually a slightly different case because the names of the doctors are printed by a nested view (I don't know if it's more complicated to index the output of nested views).
I hope I've made it clearer for you, cheers
Nicola
Thanks for writing back and for sharing these details.
Based on what you've shared, I've performed some further tests and I think I've figured out what is happening.
The Relevanssi's indexing feature, can search through the content/body of the pages/posts but not the content, that is shown through an assigned content template.
(because technically the content that is getting loaded through a content template is saved separately and not as part of the original post/page)
So in short, the output of the view that is directly part of the page/post content/body is searchable, but if that view is a part of a content template that is assigned to a page/post, then it is not searchable.
In the context of the "Cardiologia" post ( hidden link ), the view ( 'Mostra Prestazioni Medici e Sedi in Branche' ) is part of the assigned content template ( 'template-branche-amp' ) and not part of that post's content/body.
If you'll include this same content template's shortcode in the content/body of the "Cardiologia" post, its enclosed content, including the view's output would become searchable:
[wpv-post-body view_template="template-branche-amp"]
I hope this helps and please let me know if you have any follow-up questions.