Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Replicating a search query through ASP_Query
- This topic has 3 replies, 2 voices, and was last updated 6 years, 11 months ago by
Ernest Marcinko.
-
AuthorPosts
-
July 3, 2019 at 10:51 am #23578
zigasancin
ParticipantHi,
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 #23590Ernest Marcinko
KeymasterHi,
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.
July 3, 2019 at 7:45 pm #23596zigasancin
ParticipantOh, 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 #23599Ernest Marcinko
KeymasterGreat 🙂
I will try to expand this functionality in the upcoming release with documentation. I will mark this topic resolved a bit later on.
-
AuthorPosts
- You must be logged in to reply to this topic.