Relevanssi sees the table shortcode and should index the table contents. I just tested the Ninja Tables support on my test site and using the latest version of Ninja Tables, Relevanssi had no problems indexing Ninja Tables content.
I wonder what the problem is – is the problem that the Relevanssi Ninja Table indexing function does not run at all, or is the problem that it runs, but doesn’t see the table contents as expected? This can be figured out by editing the /lib/compatibility/ninjatables.php file in Relevanssi.
If you add
error_log( "Indexing Ninja Table $table_id" );
as the first line in the relevanssi_index_ninja_table()
function in that file and
error_log( $table_contents );
as the second-to-last line before the return $table_contents;
line, go save the personnel directory page and then look at the PHP error log, that should clear things out a bit.
I edited the file in Relevanssi and below is the line in the PHP error log.
[08-Jun-2020 02:56:59 UTC] Indexing Ninja Table 1381
Ok, so Relevanssi tries to index the table, but doesn’t find any content for it. How is the table set up in Ninja Tables? Is it just regular rows and columns, or is it somehow created dynamically?
It is dynamic, it pulls in data from a custom post type.
That appears to be the issue, all my tables have the data source as wp-posts. I created a table with just straight entered data and put the table on a test page. Relevanssi indexed the test page and returned it in a search result.
That’s it, then – because of the way Ninja Tables is built, Relevanssi can’t just expand the shortcode and see what it prints out. Relevanssi instead looks for the table content in the Ninja Table database and reads it from there. For dynamic tables, there’s nothing in the table.
Dynamic content in tables is a Pro feature in Ninja Tables, so I can’t tell how it’s built. Perhaps it’s possible to create a function that will gather the same data that’s in the table and pass that to Relevanssi, but I can’t tell how, as I don’t know how Ninja Tables does it.
So are you suggesting I contact Ninja Tables to ask how the data is being passed to the table? What exactly should I ask them?
For starters, you could take a look at the wp_postmeta
table. What’s in there for post_id
1381 in the _ninja_tables
fields?
There is a __ninja_cached_table_html that looks like it has all the table info.
View screen shot 1
View screen shot 2
Very good! That’s very helpful. Try adding this to functions.php and reindexing:
add_filter( 'relevanssi_post_content', 'relevanssi_index_ninja_cached_table_html' );
function relevanssi_index_ninja_cached_table_html( $content ) {
$m = preg_match_all(
'/.*\[ninja_tables.*?id=["\'](\d+)["\'].*?\]/im',
$content,
$matches,
PREG_PATTERN_ORDER
);
if ( ! $m ) {
return $content;
}
foreach ( $matches[1] as $table_id ) {
$cached_table_html = get_post_meta( $table_id, '__ninja_cached_table_html', true );
$content .= ' ' . $cached_table_html;
}
return $content;
}
That did the trick! Thank you for the expert support and working with me to get this resolved. I will be purchasing the pro version, because of your great support.
Thanks. I’ll have to see how to integrate this in to the built-in Ninja Tables support in Relevanssi – maybe see if the cached HTML exists and if it does, use that…
Can you please check one thing for me? What happens if you do this:
1. Create a new dynamic Ninja Table from posts
2. Create a new page
3. Add the table to that page
4. Save the page
Can the page now be found with something that’s in the table? I’m curious about how the cached HTML is generated; does that happen immediately, or only when the page is viewed.
If the page cannot be found by the table content, then I assume viewing the page and then updating it should fix that. Am I right?
Ok,
- Created a New dynamic Table
- Created a new page
- Added the table to the page
- Saved the page
- Rebuilt the Relevanssi index
I then searched for something in the table and the page showed up. So it looks like the cache is created when the table is created.
Hi Mikko,
I’m having the same problem using the Divi search. Any suggestions how to resolve this?
Thanks for your help.
Best regards,
Gert