Skip to main contentSkip to footer

The wpDataTables table plugin has several ways to handle tables. Some of them work with Relevanssi without problems; some don’t. You may notice that Relevanssi doesn’t index the entire table contents for wpDataTables tables (mainly imported tables). This is because the wpDataTables shortcode does not always expand to the entire table; it only features part of the table. The rest of the table is fetched using Javascript, and Relevanssi does not see that.

If you have this problem, there’s a solution. You can add this function to your site:

add_filter( 'relevanssi_post_content', 'rlv_wpdatatable' );
function rlv_wpdatatable( $content ) {
    $m = preg_match_all( '/\[wpdatatable id=(\d*)\s?.*\]/', $content, $matches );
    if ( ! $m ) {
        return $content;
    }
    global $wpdb;
    foreach ( $matches[1] as $table_id ) {
        $table_query   = $wpdb->prepare( 'SELECT * FROM `' . $wpdb->prefix . 'wpdatatables` WHERE id=%d', intval( $table_id ) );
        $table_config  = $wpdb->get_row( $table_query, OBJECT );
	    $table_content = $wpdb->get_results( $table_config->content, ARRAY_A );
        $table_value = relevanssi_flatten_array( $table_content );
        $content    .= ' ' . $table_value;
    }
    return $content;
}

This function hooks onto relevanssi_post_content and looks for [wpdatatable] shortcodes, and if it finds one, it fetches all the table contents from the database and adds them to the post content.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

How to display relevancy score

Relevanssi stores the relevance score it uses to sort results in the $post variable. Just add something like <?php echo “Score: $post->relevance_score”; ?> to your search results template to display the relevance score….

User Access Manager
Relevanssi has a conflict with User Access Manager plugin. Both plugins attach to the same `the_posts` filter hook with the…
Adjusting search throttle
If Relevanssi Premium causes out-of-memory problems, make sure you have the “Throttle searches” option checked. However, if that doesn’t work…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed