Creating a custom search page

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Creating a custom search page

This topic contains 11 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 9 years, 6 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #4170
    champton
    champton
    Participant

    I am building a custom search page and was wondering what the variable asp_data was that is being passed in the querystring when I click on more results. It shows warnings on my page when that querystring is present. See below for warnings: Thanks for your input.

    Warning: simplexml_load_string(): Entity: line 2: parser error : AttValue: ” or ‘ expected in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): ^ in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): Entity: line 2: parser error : attributes construct error in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): ^ in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): Entity: line 2: parser error : Couldn’t find end of Start Tag html line 2 in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): ^ in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): Entity: line 2: parser error : Extra content at the end of the document in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23 Warning: simplexml_load_string(): ^ in /var/www/html/seconnect/wp-content/plugins/ajax-search-pro/includes/suggest.class.php on line 23

    #4173
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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;
            else
              return false;
           } catch (Exception $e) {
              return false;
           }
        }
    

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

    Best,
    Ernest Marcinko

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


    #4179
    champton
    champton
    Participant

    I still get the warnings. I can turn off warnings but I still want to know why I am getting them. Thoughts?

    Great plugin by the way.

    #4180
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thanks!

    Are those the same warnings? The try-catch structure should prevent the ones you got before.

    Best,
    Ernest Marcinko

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


    #4181
    champton
    champton
    Participant

    The warnings go away if I simply go to /?s={phrase} but I get the warnings when I am going to /advanced-search/?kw={phrase} where I am creating a new search template. I will just edit my search.php page since the warnings go away. Thanks for your help. You have a great plugin and quick support. I appreciate you.

    #4183
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Your welcome and thank you for the kind words!

    Just a quick note: If your custom search page will look like “/advanced-search/?kw={phrase}” format, then make sure that the “$_GET[‘s’]” variable is also set to the same value. I’m almost 100% sure, that it’s needed. So a simple

    if (isset($_GET['kw'])) $_GET['s'] = $_GET['kw'];

    statement should prevent some funny unexpected behavior. I’m not sure however where to put this, I don’t know if it would work in search.php file.

    I remember someone asked something similar last week, and I found this short article about customizing search url and redirection and stuff: http://wpengineer.com/2258/change-the-search-url-of-wordpress/

    You might find it helpful as well. Have a nice rest of the day, and good luck with the coding!

    Best,
    Ernest Marcinko

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


    #4184
    champton
    champton
    Participant

    how do i make a page where all of your search results show up instead of using the WordPress search results. Your results are much better.

    #4186
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    If you set the “Override the default WordPress search results page?” option on the General Options->Behavior panel to yes, it will automatically replace the default wordpress search results with the ajax search pro ones. (that’s when it sends the asp_data variable)

    Best,
    Ernest Marcinko

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


    #4192
    champton
    champton
    Participant

    I do have that setting but I don’t get all the results. See screenshots and this is the more results querystring: ?s=Attributes&asp_data=YXNpZD0yJnF0cmFuc2xhdGVfbGFuZz0wJnNldF9pbnRpdGxlPU5vbmUmc2V0X2luY29udGVudD1Ob25lJnNldF9pbmV4Y2VycHQ9Tm9uZSZzZXRfaW5wb3N0cz1Ob25lJnNldF9pbnBhZ2VzPU5vbmUmY3VzdG9tc2V0JTVCJTVEPW5sdC1iaW9zJmN1c3RvbXNldCU1QiU1RD1vY2MtdmlkZW9zJmN1c3RvbXNldCU1QiU1RD1vY2MtcGhvdG9ncmFwaHkmY3VzdG9tc2V0JTVCJTVEPWZvcnVtJmN1c3RvbXNldCU1QiU1RD10b3BpYyZjdXN0b21zZXQlNUIlNUQ9cmVwbHkmY3VzdG9tc2V0JTVCJTVEPXdwZmJfZmlsZXBhZ2U=

    Attachments:
    You must be logged in to view attached files.
    #4196
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    What type of content are those on the ajax result list?

    The search can override the results page with only posts/pages and custom post types. If those are categories or terms, they will not show there, because it’s not possible to add them to the query object.

    Best,
    Ernest Marcinko

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


    #4197
    champton
    champton
    Participant

    OK. That makes sense. I may have to write a custom results page then. How can I decode your asp_data so I can create a custom query? Is that something that can be done by calling a function from your plugin?

    #4198
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    This is the current method for decoding:

    
    parse_str(base64_decode($_GET['asp_data']), $s_data);
    

    After that, the $s_data will contain all the information passed through as an associate array.

    You might also find the includes/hooks.php file interesting. The first function there is the one that filters the default search results with the ones from ajax search pro. If you look at line 23, it says:

    
    $res = ajaxsearchpro_search();
    

    This is the most important line there. The $res variable will contain all the search results that ajax search pro returns as an array, which might be extremely useful to you. If you stored that variable somewhere or make it global, you will have access to it in the search.php theme file.

    That might save you some time 😉

    Best,
    Ernest Marcinko

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


Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Creating a custom search page’ is closed to new replies.