Jan 8, 2019 - Geeky General, Wordpress Comments Off on WordPress search fails with error
WordPress search fails with error
After a recent upgrade, the following WordPress error was being displayed for searches:
Parse error: syntax error, unexpected 'new' (T_NEW) in search.php on line
The issue is that they made some changes in PHP 7. You can’t assign classes with a ‘&’ symbol anymore. So just remove that ‘&’ symbol and the search should work fine again (search for multiple occurrences).
PROBLEM CODE:
Search results for <strong>"<?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('"'); echo $key; _e('"'); wp_reset_query(); ?>"</strong>
FIXED CODE:
Search results for <strong>"<?php /* Search Count */ $allsearch = new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('"'); echo $key; _e('"'); wp_reset_query(); ?>"</strong>