relevanssi_do_query()
has nothing to do with this.
There’s a filter you can use: relevanssi_content_to_index
can be used to add arbitrary content to posts before they are indexed. So, for this page, you’d have to create a function that adds the post content from the child posts to the post content.
Awesome thanks for this. I was totally on the wrong path!
But if you can quickly help me one last time Mikko, I’m still not sure how to get this to work full. The empty quotes in the filter definition in your list of filters I don’t understand either. I would have thought tons of people would have this request as writing a custom query is very common, especially for things like ecommerce sites or anything using CPT.
In my functions.php file I did this:
add_filter('relevanssi_content_to_index', 'custom_query_content');
function custom_query_content($content_data) {
return $content_data;
}
And then within the while loop for my custom query I simply did this:
<?php
$content_data = get_the_content();
custom_query_content($content_data);
?>
Any chance you can assist or does anyone else have any tips? Thanks!
No, that’s not correct – the custom_query_content() function you wrote currently does exactly nothing.
Do something like this:
function custom_query_content($content) {
global $post;
$childpage_query = get_posts(
array( 'posts_per_page' => -1,
'post_type' => 'page',
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC' )
);
foreach ($childpage_query as $t_post) {
$content .= $t_post->post_content;
}
return $content;
}
Now, when the indexer calls the filter, the function will run, fetch the extra content and add it to the post content.
Awesome, huge thanks on that! Totally get it now, this is very handy, and certainly will help some folks. I do not yet need the full version of Relevanssi, but I wish you had a donation option for folks to show their appreciation of the free version of the plugin and your support for it.
Just a reminder though to anyone else reading this, you now also have to use this filter ‘relevanssi_excerpt_content ($content, $post, $query)’ in order to have the content from this section show up in the search results excerpts.
Thanks again!
I do accept donations, my PayPal account is mikko @ mikkosaari.fi. Glad you got this sorted out.