Forums › Forums › Search & Filter Pro › Can’t Get a Results Count with Oxygen Builder
Tagged: oxygen, oxygen builder, sidebar
- This topic has 3 replies, 2 voices, and was last updated 4 years, 11 months ago by
Trevor.
-
Anonymous(Private) September 16, 2020 at 2:04 am #259570
I should have mentioned specifically, I am using Search and Filter Pro with an Oxygen repeater so I don’t have access to the query name. I am using [searchandfilter id=”YOURSEARCHID” action=”filter_next_query”] to filter the Repeater’s query.
Anonymous(Private) September 16, 2020 at 2:33 am #259571Literally figured this out directly after posting this. I’ll post my solution for anyone interested.
Here is the code I used in a PHP block to display the search term and a post count:
global $searchandfilter; $sf_current_query = $searchandfilter->get(678)->current_query(); echo $sf_current_query->get_search_term(); $the_query = new WP_Query(array( 'post_type' => 'courses', )); echo $the_query->found_posts; wp_reset_postdata();
Both before this code block and before the repeater that follows I put this shortcode (so twice):
[searchandfilter id=”YOURSEARCHID” action=”filter_next_query”]I had tried this almost exactly last night (except without any arguments for $the_query) but it didn’t work. The trick was that I had to filter “$the_query” by at least one argument, in this case post_type. If I left the arguments empty or passed an empty $args, the searchandfilter shortcode wouldn’t filter. I’m assuming that shortcode is just a pre_get_posts based on the filter parameters and there needs to be at least one parameter for pre_get_posts to work.
Either way, I believe I have it figured out – thanks for making a great plugin! It would be great to get more direct Oxygen Builder support in the future as it’s an amazing builder for people who can code but in the meantime, things are working so I’m happy!
-
AuthorPosts