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, 1 month ago by Trevor.
-
Anonymous(Private) September 16, 2020 at 2:01 am #259569
Hi there,
I just purchased the pro version and was able to get nearly everything to work properly with Oxygen Builder using the guide posted by Jan Langhans here:
https://support.searchandfilter.com/forums/topic/search-and-filter-pro-oxygen-builder-repeater/
I was even able to make it work with an Oxygen Archive template even though that post said it wasn’t possible (although I still have to enter the page url for where the template will appear).
Additionally, I was able to display the current search result by using a PHP block and using this code:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(678)->current_query();
echo $sf_current_query->get_search_term();I wrote out everything I can do just to show why it is so frustrating that I can’t figure out how to simply display the total results count after being filtered by Search and Filter Pro. I tried echo $sf_current_query->found_posts; directly after the code I have above and that comes back as null and displays nothing. I tried creating a new wp query and using found_posts with that but that just displays the total count unfiltered by search and filter. I have a feeling there’s some simple way to access the total results like the get_search_term() function above but I just can’t figure it out.
Any help would be greatly appreciated!
Anonymous(Private) September 16, 2020 at 2:04 am #259570I 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