WPIntell

Source evidence

Custom search template with Oxygen builder & WPML

Relevanssi Live Ajax Search · support · 2024-03-21T11:02:00+00:00

complaintsentiment
highseverity
0.9relevance
3replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

3 / 22 rows with source links

13.6% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

19 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
sergio79 unresolved
Hi 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?

Comments

3 shown
Mikko Saari 2024-03-21T11:05:00+00:00

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.

sergio79 2024-03-21T11:41:00+00:00

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

Mikko Saari 2024-03-21T11:47:00+00:00

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?