Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Replicating a search query through ASP_Query › Reply To: Replicating a search query through ASP_Query
July 3, 2019 at 4:26 pm
#23590
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.