Forums › Forums › Search & Filter Pro › Manually get results
- This topic has 4 replies, 3 voices, and was last updated 6 years, 11 months ago by Ross.
-
Anonymous(Private) November 14, 2017 at 9:56 pm #141984
Is there a way to manually get the results, without having to use a results page.
I want to be able to create a query, use search and filter on it, and then access the results all in the backend.I have a custom api that will accept a search term, build a query, and return the categories for the search term. I want to attach search and filter to this and then get the categories search and filter generates.
Trevor(Private) November 15, 2017 at 11:20 am #142055I am not entirely certain what you are doing with this, but WordPress needs to post the query to a page, which you could then use this to grab the query array:
$sf_current_query = $searchandfilter->get(7050)->current_query()->get_array();
Where you change the ID to the form ID of your form.
Ross Moderator(Private) November 28, 2017 at 6:50 pm #144371Hi Cody
Off the top of my head, I’m not sure S&F will work as is in the backend (it was never designed for that).
S&F runs different code depending on whether you are in wp-admin or not.
Generally speaking though, you can attach S&F to any query you create. So there might be an option for you to create your query in an ajax call (S&F should work in wp-ajax, even though its technically in admin) and you could wrap your results as a JSON object, from which you would need to parse with Javascript and take any necessary actions after that .
In order to add S&F to your query you would need to add the argument
search_filter_id
.eg:
$args = array( 'post_type' => 'post', 'search_filter_id' => 1234 ); $my_query = new WP_Query($args);
Hope that helps.
Best
-
AuthorPosts