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

MemberPress Downloads add-on

…need to tell Relevanssi to look for mpdl-file posts instead of attachment posts using the relevanssi_get_attachment_posts_query filter hook. By default, Relevanssi looks for posts with the post type attachment, post status inherit and a suitable MIME type. These all need to be changed, because the Downloads posts have the post……type mdpl-file, status of publish and no MIME type. Add this to your site: add_filter( ‘relevanssi_get_attachment_posts_query’, ‘rlv_mpdl_query’ ); /** * Filters the MySQL query for getting the attachments. * * Finds and replaces the ‘attachment’ post type restriction to look for mpdl-file * posts and also changes the post_status filtering…

WooCommerce: Return only exact matches for SKU searches

…_sku custom field (because otherwise, SKU search will not find anything), and the search query must match the SKU exactly. Add this code to your site: add_filter( ‘relevanssi_hits_filter’, ‘rlv_sku_exact_match’ ); function rlv_sku_exact_match( $hits ) { global $wpdb; $post_ids = $wpdb->get_col( $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE meta_key = ‘_sku’ AND……)[‘object’]; return in_array( $hit_object->ID, $post_ids, false ); } ); return $hits; } Any searches that match an SKU in the database should only return the product matching the SKU. If you index product variation SKUs for the main product, the function above won’t work. When searching for product variation SKUs,…This little filter function works on relevanssi_hits_filter. When a search query is made that matches an SKU (or any other custom field, but SKUs are the most likely scenario here), only results that match the SKU will be returned. For this to work, Relevanssi must be set to index the…

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