TypeError: instantsearch.connectors is undefined

I’m on a Trail account, trying to make a custom (datepicker) widget. For this, I’m playing around with connectors as in:

However, I get the TypeError mentioned in the topic subject. In a child theme, I have added the following to the plugin instantsearch.php:

function hideresults(renderOpts, isFirstRendering) {
  if (isFirstRendering === true || renderOpts.results.query.length === 0) {
    $('.container.content-grid>.row').show();
    $('#algolia-results').hide();
  }
  else {
    $('.container.content-grid>.row').hide();
    $('#algolia-results').show();
  }
}
var autohide = instantsearch.connectors.connectHits(hideresults);
search.addWidget(autohide());

This breaks the search entirely, with the above error.

Any ideas? Is this a limitiation of the Trail status?


update: I’m using version 2.11.2 of the WordPress Plugin

@n.wenting The version of InstantSearch.js used in Wordpress is 1.x while connectors are only available in 2.x. Your best bet here would be to update the wordpress theme to include InstantSearch 2.x and benefit from connectors.

cc @rayrutjes

Thanks for your reply! So I was really optimistic and did this in my child theme:

function aa_algolia_enqueue_scripts() {
	wp_deregister_script( 'algolia-instantsearch' );
	wp_register_script( 'algolia-instantsearch', 'https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.2', '', '', true );
}
add_action( 'wp_enqueue_scripts', 'aa_algolia_enqueue_scripts' );

function aa_algolia_enqueue_styles() {
	wp_deregister_style( 'algolia-instantsearch' );
	wp_register_style( 'algolia-instantsearch', 'https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.2/dist/instantsearch.min.css' );
}
add_action( 'wp_enqueue_styles', 'aa_algolia_enqueue_styles' );

Which didn’t work. I guess updating the instantsearch version is a little more involved, right? Will the plugin get an update anytime soon?

Just to be complete: I’m now presented with a “wp.template is not a function” javascript error.

I have somthing working now after including the dependencies:

function aa_algolia_enqueue_scripts() {
	wp_deregister_script( 'algolia-instantsearch' );
	wp_register_script( 'algolia-instantsearch', 'https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.2', array( 'jquery', 'underscore', 'wp-util' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'aa_algolia_enqueue_scripts' );

function aa_algolia_enqueue_styles() {
	wp_deregister_style( 'algolia-instantsearch' );
	wp_register_style( 'algolia-instantsearch', 'https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.2/dist/instantsearch.min.css' );
}
add_action( 'wp_enqueue_styles', 'aa_algolia_enqueue_styles' );

So I guess I can continue experimenting with the connectors, but do feel free to add feedback…

1 Like