Tagged: gmw_pt_search_query_args, gmw_pt_tax_query, search
- This topic has 4 replies, 2 voices, and was last updated 5 years, 9 months ago by
derbra1513.
-
AuthorPosts
-
October 8, 2016 at 4:21 am #54692
derbra1513
MemberFirst of all I love your plugin! Its working great and Ive almost managed to launch my website but need to filter and search using the geolocation filter. I managed to find a thread that helped a bunch and it works great.
1234567891011121314function find_open_courses( $args, $gmw ) {//if form ID is 8 or 16 then run the filterif ( $gmw["ID"] == 1) {$title = $_GET['search_title_test'];//we only need to modify the meta_query argument$args = array('s' => $title,);}return $args;}add_filter( 'gmw_pt_search_query_args','find_open_courses', 10, 2 );The problem I am having is now I would like to filter the posts through custom taxonomies. I have 2 City, and Category. Ive managed to grab all the items that the user selects, put that into an array but when I try to pass it through a filter it doesn’t work. Any help would be appreciated. Ive attached the code I am using and the URL that is generated. I have also tried filtering this with the ‘gmw_pt_tax_query’ filter and the ‘gmw_pt_search_query_args’
12345678910111213141516function filter_results( $args, $gmw ) {//if form ID is 8 or 16 then run the filter$cat = $_GET["categories"];$cat_array = array();foreach ($cat as $n){$cat_array[] = $n;}print_r($cat_array);if ( $gmw["ID"] == 1) {$args = array( "relation" => "AND" );$args[] = array("taxonomy" => "category","field"=> "slug","terms" => $cat_array);}return $args;}add_filter( "gmw_pt_tax_query","filter_results", 10, 2 );October 8, 2016 at 1:30 pm #54694derbra1513
MemberOk so I managed to get the queries to filter properly I was misusing the gmw_pt_tax_query filter. Now the problem I am having is that if the user filters enough on the form and gets to the point where qp_query can’t find any posts it breaks the search and the rest of the site load.
123456$args = array('s' => $title,'tax_query' => apply_filters( 'gmw_pt_tax_query', $args_tax ),);}return $args;`
So right now everything is filtering fine but is there a condition I can add if no posts are found?
October 8, 2016 at 1:34 pm #54698derbra1513
MemberSorry for the broken code, I can’t seem to paste it without breaking the markup…
October 8, 2016 at 2:33 pm #54702Eyal Fitoussi
MemberHello Debra1513 and thank you for the feedback.
Your script above seems to be OK and looks like it should work. However, I can’t see the live site ( the link above doesn’t work ) so I can’t see the issue.
However, it could be the the URL is getting too long because of the categories and might be the cause for the error. But I can’t be sure.
One thing you can try is to replace the category slug in the URL with the category ID, which will make the URL much shorter, and see if that works.
If you can get the page live maybe I could help by looking at it.
Sorry for the broken code, I can’t seem to paste it without breaking the markup…
Wrapping the code within PRE tags ( instead of the code tags ) should solve the issue .
October 8, 2016 at 3:40 pm #54714derbra1513
MemberThanks for the reply!
So Ive managed to get my multiple taxonomy filters to work. However If the user selects filters that results and 0 posts are found, My page breaks.
I am just curious if there is a condition that I can use if no posts are queried I can send them to a no posts found page or something similar.
-
AuthorPosts
You must be logged in to reply to this topic.