So, if you add this and rebuild the index, you get no results for “penguin”?
add_filter('relevanssi_content_to_index', 'add_content_after_post', 10, 2);
function add_content_after_post($content, $post) {
$content .= " penguin";
return $content;
}
Thread Starter
Sany
(@sannny)
Hi Mikko,
yes, it works. I’ve just done something wrong with the filter.
Awesome, thank you!
Have a nive weekend.
saNNNy
Thread Starter
Sany
(@sannny)
Hi again,
I have another question. The content indexing is working fine now, but if I want to index content with dots it doesn’t work.
E.g. I implemented
add_filter('relevanssi_content_to_index', 'add_content_after_post', 10, 2);
function add_content_after_post($content, $post) {
$content .= "june.testdata.SQL";
return $content;
}
When I rebuild the index and search for june.testdata.SQL or “june.testdata.SQL” I don’t get any results. How can I make this work?
saNNNy
Relevanssi removes all dots, as they are mostly pointless for searching.
However, searching for june.testdata.SQL should work, as the dots are also removed from the search queries. The code you have here doesn’t have a space before the new content; that’s a likely reason why this is not working. Try with a space and see if that works better.
Thread Starter
Sany
(@sannny)
Yep, it was because of the missing space, thanks.
Ok, now the final problem is: I add the content with a shortcode.
My code (outcommented = what I tried, always with rebuilding the index):
//function list_files($atts, $content, $post) {
function list_files($atts, $content) {
//global $post;
$atts = shortcode_atts(array('folder' => '', 'target' => ''), $atts);
$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'] . '/' . $atts['folder'];
$output_dir = $upload_dir['baseurl'] . '/' . $atts['folder'];
$files = is_dir($dir);
if(!$files) {
$content .= '<div>Dir not found ' . $output_dir . '</div>';
}
else {
$files = scandir($dir);
natcasesort($files);
$content .= '<ul>';
foreach($files as $file) {
$content .= '<li><a href="' . $output_dir . '/' . $file . '" target="' . $atts['target'] . '">' . $file . '</a></li>';
}
$content .= '</ul>';
// $content = apply_filters('relevanssi_content_to_index', 'powershell_files');
// $content = apply_filters('the_content', $content);
// $content = apply_filters('relevanssi_content_to_index', $content, 10, 2);
}
return $content;
}
add_shortcode('listfiles', 'list_files');
// add_filter('relevanssi_content_to_index', 'list_files', 10, 2);
WP Editor: E.g. [listfiles folder=”documentation” target=”_blank”]
Frontend: E.g.
– mai.testdata.SQL
– june.testdata.SQL
– july.testdata.SQL
– …
I want to search for “july.testdata.SQL” but I don’t get this. How can I add the content to index which is created in this shortcode??
Is this printing out the right content in the frontend? If so, it should definitely work with Relevanssi. However, you need to make sure Relevanssi is set to index shortcodes, and you need to rebuild the index. You also need to note that Relevanssi only sees the content of the shortcode as it was when the index for the post in question was last rebuilt.
Thread Starter
Sany
(@sannny)
However, you need to make sure Relevanssi is set to index shortcodes, and you need to rebuild the index.
This was the reason. Now everything is working perfect.
Thank you very much.