Replicating a search query through ASP_Query

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 Ernest Marcinko 4 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #23578
    zigasancin
    zigasancin
    Participant

    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!

    #23590
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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 :)


    #23596
    zigasancin
    zigasancin
    Participant

    Oh, I had problems with the search instance ID earlier and disabled it by mistake in my tests. It works now as intended!

    Thanks,
    Ziga

    #23599
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Great 🙂

    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 :)


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

You must be logged in to reply to this topic.