Reply To: Is it possible to add additional Views templates?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Is it possible to add additional Views templates? Reply To: Is it possible to add additional Views templates?

#9540

Ernest Marcinko
Keymaster

Hi Luyen,

For the layouts I would recommend using filters instead of the templates, but it's a personal prefenrence. I usually prefer filters for all cases.

I would use the asp_results filter in your case, because it has all the information you might need. As an example code:

As you can see, this filter passes the results array and the search ID, which is exactly what you need to decide what to do exactly for each search instance.

—————-

The additional query problem is a bit more complicated. I had to run a few tests to see if it's even possible, as I have never thought of this possibility. Just recently I have implemented a search API, documentation is under construction yet. Long story short, there is a class called ASP_Query, which is very similar to the classic WP_Query class.

I haven't made a list of practical examples yet, but you can check all the possible arguments on this gist url: https://gist.github.com/anag0/60f0de34e933ad2e0ac580cc1050ff57

That is the class you will need in order to make this work. Now, before we start, you will have to make 1 modification in a plugin file, otherwise it won't work unfortunately.
Open up the plugins\ajax-search-pro\includes\classes\ajax\class-asp-search.php file on your server and scroll to line 73, which should be this:

$results = apply_filters('asp_only_non_keyword_results', $results);

change that to:

$results = apply_filters('asp_only_non_keyword_results', $results, $id, $s);

Okay. Now the asp_only_non_keyword_results filter passes the search ID as well, which is mandatory, and useful as well. Don't worry about this change, I'm going to include it in the upcoming release, so it won't get lost after an update.

Using this filter, it's now possible to parse additional results and append them to the results list. An example function I used:

This code executes another query with the search phrase “hello” and appends the results to the beginning of the current results list. Leave the '_ajax_search' argument on true, it's very important to get the correct results format in ajax context.

You can of course then extend this basic example with the switch statement from the other example above, to do different queries for each search instance.

Best,
Ernest Marcinko

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