Forums › Forums › Search & Filter Pro › Filter Current Archive Category
Tagged: category
- This topic has 17 replies, 2 voices, and was last updated 6 years, 1 month ago by Anonymous.
-
Anonymous(Private) October 5, 2018 at 10:07 pm #190280
Hello, I was wondering if it is possible that on an archive page of a site to have the filter only apply to the current category.
For example if I am on page.com/category/filtered that on search that the filter would only filter those posts.
This would be in the archive.php file in our build which would mean it would have to be agnostic to category number.
Is it possible to have one filter that can be set in a function to grab the id of the current category and upon filter stay restricted to that category?
Trevor(Private) October 8, 2018 at 12:14 pm #190333If you are using the Post Type Archive display results method, you can do as you want. On the General Settings tab you can select to Auto Detect the Category.
On the Display Results tab, you can select to stay within the category pages.
You also need to add the category to the form, but use custom CSS to hide that field.
Trevor(Private) October 8, 2018 at 3:17 pm #190404Here (the third red box in this shot):
https://www.screencast.com/t/Qi1FiS6F0S
And here (the second red box):
Anonymous(Private) October 8, 2018 at 3:27 pm #190414So that is working as intended, but it seems our client wants to be able to direct users to pages that are archives of child categories. For example if we have a parent category that is Alerts and it has a child category of say emergency.
If a user is linked to domain.com/category/emergency would those settings keep it restricted to emergency or upon search would it search the parent category as I am sure the auto detect would pick up the parent.
Anonymous(Private) October 8, 2018 at 3:43 pm #190430function wpd_sort_by_meta( $query ) { $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $category = get_the_category(); var_dump($category); if ( $query->is_archive() && $query->is_main_query() ) { $query->set( 'cat', $category ); $query->set( 'meta_key', 'start_date' ); $query->set( 'paged', $paged ); $query->set( 'orderby', 'meta_value' ); $query->set("search_filter_id", 18437); } } add_action( 'pre_get_posts', 'wpd_sort_by_meta' );
That is my query that displays the initial results for the archive page which initially works. The issue is upon form submission the category changes so on initial load if I dump category or category[1] it will be a value of 4904 which is the id of the category but that changes upon form submission.
-
AuthorPosts