Reply To: Requesting some information for plugin template modification

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Requesting some information for plugin template modification Reply To: Requesting some information for plugin template modification


Ernest Marcinko


I will try to explain everything I can in details. While customizations are not part of the support, I gladly help, but please note that for this reason I cannot take responsibility if some of these suggestions won't work.

There are two (possible) issues I can see with the code there, one is a minor issue, the second one is bigger.

The minor (possible) problem is that the return statement is within the conditional statement. I'm not sure if that is intended, but if the

return $results;

is not executed, then no results are returned if the conditional statement fails. If that is intended, then I suggest changing that to:

if ( something ) {
    // Do your stuff here as before
    return $results;
} else {
    return array();

Because the handler expects an array of results, even if it's empty.

The second problem is that is_page(985) is always going to return false. This code is exectued in an ajax context, which is a separate process from the page view – so there is no information in that process of the currently viewed page, where the request is sourcing from. So calls like is_page(), is_home(), is_single() etc.. are not going to work, because this is not a pageview, it's an ajax request.

There are two ways developers deal with this situation:
1. To send the page ID along with the ajax request, and check that variable within that code. This however requires to change the plugin code directly, which is not what we are aiming for.
2. Using a different method with the given variables at the time of the ajax request.

Right now the best bet is to try to identify the search instance differently. If you take a look at the ajax response via console, you can see the variables passed on to the ajax handler, which are also accessible in that particular code snippet!
As an example, I did a search on the demo:

As you can see variables passed on to the handler are:


The one that is interesting for us is $_POST['asid'], which contains the instance number of the search, that started the ajax request.

If page 985 has a different search instance as the other pages, makes it possible to distinguish from others. I would use this snippet as a sample:

Don't forget to change the 1234 to the search instance number you are using.


Disabling scrolling: On the Theme Options -> Vertical results panel change the viewport option to a very high number, like 100 or so:


Child theme: I just checked, it's indeed not returning the correct directory when using a child theme, I will have to look into that.
For a possible temporary fix, open up wp-content\plugins\ajax-search-pro\includes\classes\etc\class-asp_helpers.php file and scroll to line 145, which should be:

$theme_path = get_template_directory() . "/asp/";

and change that to:

$theme_path = get_stylesheet_directory() . "/asp/";

If that works, then use it, I'm definitely going to fix this in the upcoming release, so you should not worry about loosing this change.

Ernest Marcinko

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