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