Conversation
supportHi Mikko, I’m using Relevanssi + Relevanssi Live Ajax Search with Oxygen builder and WPML, without any problems. To make it work I need to set this function: add_filter( ‘relevanssi_live_search_mode’, function() { return ‘wp_query’; } ); As you know, oxygen builder doesn’t use themes, so I wanted to customize the search-results.php and I tried to set my folder like this: add_filter(‘relevanssi_live_search_results_template’, function ( $location ) { return plugin_dir_path( FILE ) . ‘/live-ajax-search/search-results.php’; }); Unfortunately this causes the plugin to stop working completely, due to the following errors: PHP Warning: Attempt to read property “found_posts” on null in /…/search-results.php on line 28 PHP Warning: Undefined variable $wp_query in /…/search-results.php on line 28 PHP Warning: Undefined array key “s” in /…/search-results.php on line 82 I think it’s related to ‘relevanssi_live_search_mode’ what do you think?
Correct. If you’re using the WP_Query mode, you need to base your custom template on the search-results-query.php template file. When you use the WP_Query mode, the search results are not in the global $wp_query (that doesn’t work with WPML), but in global $relevanssi_query variable.
I understand, thanks Mikko. I did a test by calling up my custom template like this: add_filter( ‘relevanssi_live_search_results_template’, function ( $location ) { return plugin_dir_path( FILE ) . ‘/live-ajax-search/search-results-query.php’; }); but I get this error 🙁 PHP Fatal error: Uncaught Error: Call to a member function have_posts() on null in /…/live-ajax-search/search-results-query.php:25
That means the $relevanssi_query variable, which should be an instance of WP_Query, is a null. That suggests the Live Ajax Search is not running correctly. I don’t know why that is happening, since the plugin is clearly running and loading the template. If you want to debug this, see what happens in the class-relevanssi-live-search-client.php in the show_results() function. This should run and create the results in the global variable: global $relevanssi_query; $relevanssi_query = new WP_Query( $args ); $template = 'search-results-query'; What’s the problem? Does this not run? Or does this run, but the global variable is unavailable for some reason?
Correct. If you’re using the WP_Query mode, you need to base your custom template on the search-results-query.php template file. When you use the WP_Query mode, the search results are not in the global $wp_query (that doesn’t work with WPML), but in global $relevanssi_query variable.
I understand, thanks Mikko. I did a test by calling up my custom template like this: add_filter( ‘relevanssi_live_search_results_template’, function ( $location ) { return plugin_dir_path( FILE ) . ‘/live-ajax-search/search-results-query.php’; }); but I get this error 🙁 PHP Fatal error: Uncaught Error: Call to a member function have_posts() on null in /…/live-ajax-search/search-results-query.php:25
That means the $relevanssi_query variable, which should be an instance of WP_Query, is a null. That suggests the Live Ajax Search is not running correctly. I don’t know why that is happening, since the plugin is clearly running and loading the template. If you want to debug this, see what happens in the class-relevanssi-live-search-client.php in the show_results() function. This should run and create the results in the global variable: global $relevanssi_query; $relevanssi_query = new WP_Query( $args ); $template = 'search-results-query'; What’s the problem? Does this not run? Or does this run, but the global variable is unavailable for some reason?