Reply To: Creating a custom search page


Ernest Marcinko


The asp_data variable holds the details about the current state of options of the search if the “Override the default WordPress search results page?” option is enabled on the General options panel. On an ajax request this is sent as post data, but here get is used for various reasons for now. This is going to change in the upcoming version.

For the warning message: I don't exactly know what is the cause, but it appears that in some cases a non-utf8 header is recieved while trying to parse the suggestions file. If you open up that file in wp-content/ajax-search-pro/includes/suggest.class.php and check lines 14-39, you should see a function there named getKeywords($q)

Try to replace that function with this one:

    function getKeywords($q) {
      $q = str_replace(' ', '+', $q);
      $method = $this->can_get_file();
      if ($method==false) {
        return array('Error: The fopen url wrapper is not enabled on your server!');      
      $_content = $this->url_get_contents($this->url.$q, $method);
      if ($_content=="") return false;
      try {
        $_content = mb_convert_encoding($_content, "UTF-8");
        $xml = simplexml_load_string($_content);
        $json = json_encode($xml);
        $array = json_decode($json,TRUE);
        $res = array();
        if (isset($array['CompleteSuggestion'])) {
          foreach($array['CompleteSuggestion'] as $k=>$v) {
            if (isset($v['suggestion']))
              $res[] = $v['suggestion']['@attributes']['data']; 
            elseif (isset($v[0])) 
              $res[] = $v[0]['@attributes']['data']; 
        if (count($res)>0)
          return $res;
          return false;
       } catch (Exception $e) {
          return false;

This will try to convert the encoding first, and return without errors if anything fails.

Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)