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

Auto-redirecting with one search result

…going through the search results page, that looks like this: add_action( ‘template_redirect’, ‘search_term_redirect’ ); function search_term_redirect() { if ( is_search() ) { global $wp_query; if ( ‘term’ === $wp_query->query_vars[‘s’] ) { wp_redirect( ‘http://www.example.com/target-page/’ ); exit(); } if ( ‘word’ === $wp_query->query_vars[‘s’] ) { wp_redirect( ‘http://www.example.com/another-target-page/’ ); exit(); } } }……wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) ); exit(); } } } This is not Relevanssi-specific and works just fine even without Relevanssi. If you are using Relevanssi on a multisite system, you need a small change to the code: add_action( ‘template_redirect’, ‘one_match_redirect’ ); function one_match_redirect() { if ( is_search() ) { global…If you want to auto-direct the user directly to the result if there’s just one result for the search, that’s quite easy. Add the following code to your site: add_action( ‘template_redirect’, ‘one_match_redirect’ ); function one_match_redirect() { if ( is_search() ) { global $wp_query; if ( 1 === $wp_query->post_count ) {…

Direct access to the query engine

Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some unfortunate limitations and reduces the general usability of the plugin. You can, however, access the query engine directly. There’s a function called relevanssi_do_query(), which can be used to do search queries…

Relevanssi Premium as a Composer package

If you want to install Relevanssi Premium as a Composer package, you can use the following URL to fetch the latest version: https://www.relevanssi.com/update/fetch_latest_version.php?api_key=XXX Replace XXX with your valid API key. The URL will always return the latest version of the plugin files. If you want a specific version, you can……use the following: https://www.relevanssi.com/update/get_version.php?api_key=XXX&version=2.20.1 The Composer package should look something like this: { “type”: “package”, “package”: { “name”: “relevanssi/relevanssi-premium”, “version”: “2.20.1”, “type”: “wordpress-plugin”, “dist”: { “type”: “zip”, “url”: “https://www.relevanssi.com/update/get_version.php?api_key=XXX&version=2.20.1” }, } } WP CLI also supports installing plugins from URLs. You can do this to install Relevanssi Premium: wp plugin……the api_key parameter, you’ll be prompted for your user name and password. Use your Relevanssi.com account user name (not the login email) as the user name and your API key as the password. These can be stored in auth.json, so you can commit your composer.json without your API key leaking….

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