Skip Navigation

[Closed] Output of views inserted in a layout is not being searchable by Relevanssi

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Waqar 1 year, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2554881

Hi, a few months ago I asked for your help to index the output of Views (link to the request https://toolset.com/forums/topic/make-views-output-searchable-by-relevanssi-indexing-views/, reply #2510885). You answered me that "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."

I think you understand that one of the main strenghts of Toolset is to create dynamic content using content templates, so I hope there is a way to solve this problem.

I forwarded your answer to Mikko Saari (Relevanssi developer), and asked him if he can do something about that. He answered me the following:

--- start of Relevanssi reply ---
I still believe this is possible, but unfortunately, I need to learn more about Toolset data structures to tell you how. I'd need to know two things:

How can Relevanssi tell which views are embedded in the post?
How can Relevanssi access the content that the view embeds?

With these, it would be possible to create a filter function that will tell Relevanssi what content to index. I was trying to learn this from the Toolset views with my questions in December, but it looks like they don't want to answer these questions; I guess they don't understand what we're trying to achieve here. There must be a method to do this; otherwise, Toolset couldn't function as it does.
--- end of Relevanssi reply ---

Could you please give me the information requested by the author of Relevanssi? If it would be helpful I can give you his direct contact information.

Thanks,
Nicola

#2555065

Hi Nicola,

Thanks for the follow-up and for sharing Mikko's response.

I'm going to review the discussion in these two tickets and will need to perform some more tests, to answer these specific questions.

I'll get back to you as soon as this testing completes.

regards,
Waqar

#2555761

Hi Nicola,

I'm going to share my findings, both for you and for the Relevanssi developer, just so that it is clear how the content handling works in Toolset, what is missing, and how this can be solved.

First, the specific question that they asked:

> How can Relevanssi tell which views are embedded in the post?
> How can Relevanssi access the content that the view embeds?

- Both these questions are not relevant here, because Relevanssi can already read and index the content coming from the views when they are embedded in the post content/body of a page/post.

The challenge here is that when a Toolset content template is assigned to a post/page, the content saved in that template is used to show the content on the frontend.
(those content templates have their own post type and post content/body etc, in the database)

But, since Relevanssi only looks for and indexes the post content/body of the original post/page, it can't associate the content added in the assigned content template with the assignee post/page.

Here are the simple steps to further clarify what I mean:

1. On a clean WordPress install, add some content like 'this is summer season' in the content/body of the default post 'Hello world!'.

2. Activate the Relevanssi plugin and perform a text search for 'summer' and this 'Hello world!' post will show in the results.

3. Next, activate the Toolset Blocks plugin and create a content template 'CT for Posts' and assign it to the "Posts" post type and remove the text 'this is summer season' from the 'Hello world!' post and add it in the template 'CT for Posts'.

4. After that, create the index of the Relevanssi plugin again, and this time when you'll search for 'summer', the 'Hello world!' post will not show in the results, because Relevanssi has no way of associating content attached through the content template.

This test and explanation will make it clear, what is missing and why.

As for the solution, the filter 'relevanssi_content_to_index' from Relevanssi and the 'has_wpv_content_template' and the 'render_view_template' functions from Toolset can be made to work together.

The 'has_wpv_content_template' function returns the ID of the assigned content template whereas the 'render_view_template' function generates the content of the content template, as explained in the documentation:
https://toolset.com/documentation/programmer-reference/views-api/#has_wpv_content_template
https://toolset.com/documentation/programmer-reference/views-api/#render_view_template

Here is what the complete function will look like:


add_filter( 'relevanssi_content_to_index', 'custom_include_toolset_content_template', 10, 2 );
function custom_include_toolset_content_template( $content, $post ) {
	$has_ct_assigned = has_wpv_content_template( $post->ID );
	// check if the current post has a content template assigned
	if ( $has_ct_assigned > 0 ) {
		// if yes, include the content rendered through the assignment content template too
		$content .= render_view_template( $has_ct_assigned, $post->ID );
	} 

	return $content;
}

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2558073

Hi Waqar,
thanks for your very detailed reply, it took me a while to answer because I tried to make work the function you posted me but, unfortunately, there's something that's going wrong. If I paste your code in the file functions.php Relevanssi is unable to perform the indexing. Maybe there's something with the render_view_template() function.
I turned on WP Debug but I don't get errors, just warnings not related with this issue.
Do you have any idea why it's not working?

Thanks,
Nicola

#2558485

Thanks for writing back. It is strange that the code is not working.

Can you please share the temporary admin login details of the website? I'll also need your permission to download a clone/snapshot of the website in case it needs to be investigated on a different server.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2564721

Hi, I haven't received any feedback in the last week, do you have any news?

Thanks,
Nicola

#2565027

Just wanted to share a quick update that I'm still working on this.

Will share the detailed findings, within the next few hours. Thank you for your patience.

#2566517

Thank you for waiting.

During testing on my own multisite network, I couldn't reproduce this issue with the search, even with that custom code enabled.

This suggests that something specific to your website's setup and/or server is involved. Your website has an automatic broadcasting plugin active, which can interfere with the way individual posts are handled.

I don't have the FTP access for your website, but here are some quick tests that I'll recommend:

1. Please see if the search starts working if that custom code is removed.

2. Also, test if the search works with the code added, but with all extra plugins disabled.
(i.e. keeping only the Toolset and the Relevanssi plugins active)

The topic ‘[Closed] Output of views inserted in a layout is not being searchable by Relevanssi’ is closed to new replies.