Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Replicating a search query through ASP_Query
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 4 years, 5 months ago.
- AuthorPosts
- July 3, 2019 at 10:51 am #23578
Hi,
thanks for making Ajax Search Pro!I’m developing a search integration and I’ve stumbled upon a problem. I’m basically trying to replicate the search query and so I looked at the code and found that the ASP_Query class could be used for that, however, I’m not getting the same results as I see them in the Ajax Search Pro suggestions list. From what I see looking at the code, I’d need to filter the query arguments with the WD_ASP_SearchOverride_Filter class to get the same results or am I missing something here?
Example: Lets say that I’m doing a search for “test”
$args = array( 's' => 'test', 'posts_per_page' => 20, 'page' => 1 ); $query = new ASP_Query( $args );
How could I filter the args or the query in this case? Is there another class or a helper function?
Thanks for your help!
July 3, 2019 at 4:26 pm #23590Hi,
Well, the ASP_Query class is not yet documented, as it is not yet finished to work in live APIs. Your example is almost perfect, but you need to pass the search ID (when you create a search instance, it is in the generated shortcode) as the second argument, so that the search instance data is parsed as the default arguments:
$args = array( 's' => 'test', 'posts_per_page' => 20, 'page' => 1 ); $query = new ASP_Query( $args, 1 ); // Passing on the search instance ID $posts = $query->posts;
..then you can go through the posts:
foreach ($posts as $post) { }
..I think you can even do this:
foreach ($posts as $p) { global $post; setup_postdata( $p ); // Now the $post variable is set, and you should access the theme functions // get_the_ID(), get_the_title() ...etc.. }
I am not sure about the last one though.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
July 3, 2019 at 7:45 pm #23596Oh, I had problems with the search instance ID earlier and disabled it by mistake in my tests. It works now as intended!
Thanks,
ZigaJuly 4, 2019 at 9:30 am #23599Great 🙂
I will try to expand this functionality in the upcoming release with documentation. I will mark this topic resolved a bit later on.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.