Home › Toolset Professional Support › [Resolved] How to show the chosen taxonomies as filters using shortcodes?
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Tagged: Custom search, Paginated lists, Views, Views plugin
Related documentation:
This topic contains 8 replies, has 2 voices.
Last updated by Minesh 6 years, 10 months ago.
Assisted by: Minesh.
Hi,
Say I have 2 categories: music and art.
I can easily create views that use shortcode to determine what posts to show based on categories combinations.
like this:
[wpv-view name="view-name" categories="xxxx"] (indicative shortcode)
My question is:
is there a way to automatically display the taxonomies I specified in the shortcode and display it as filters?
I can do this as a custom search, but as far as I understand, I can't specify values in the custom search shortcode.
I want to be able to put in the shortcode:
[wpv-view name="view-name" categories="music, art"]
then I get the posts that has either of these categories, but also I but radio buttons that enables users to filter the posts that has "music" category only.
The website I am preparing will have thousands of pages that displays posts like this. from one side I can't create a custom search for every page because it will be endless work, and from the other side if I used the shortcode only, the users will get a dump of posts that are mixed together.
thanks in advance.
Hello. Thank you for contacting the Toolset support.
Well - there is no such feature exists to add taxonomy options for taxonomy filter manually.
The only way I can think of for you is to setup such filter is you need to add your taxonomy filter normally and later on use javascript or jQuery to remove the unwanted items from your taxonomy dropdown.
Hi,
Thanks for the reply.
I don't think that you understood my question. I don't want to display taxonomy manually. I want to display the taxonomy automatically as I mentioned.
what I am asking is that I created a view using taxonomy "set by shortcode attribute".
so I want to display posts that are either in the "music" or "art" categories. so I used this shortcode:
[wpv-view name="view-name" categories="music, art"]
the shortcode works perfectly, but it shows the posts mixed together (e.g. if the music category has 5 posts and the arts category has 10 posts, I get a combined view showing 15 posts).
this is perfect, except that I can't separate the "music" posts from the "arts" posts.
My question is: is there a way to show a filter that has the chosen categories {music and art} so people can separate the arts posts from the music posts?
I know that I can do so by using custom search, but custom search does not have shortcode parameters.
please have a look at the attached sketch to get the idea.
I have added 2 screenshots for 2 mockups. the one with "what i can achieve" is the normal case. while the "what I want to achieve".
can you please read my initial and followup photos.
thankns,
My bad that I was not able to explain you well. I understand your requirement and thank you for screenshot and all required details.
What I mean to say is you are filtering the view's with shortcode attribute and you want that passed terms to shortcode attributes to display as filter, so there is no such feature exists until until you use javascript or jQuery.
I know that I can do so by using custom search, but custom search does not have shortcode parameters.
==> You can build custom search with shortcode parameter as well but the thing here is you need to add your taxonomy filter as normal filter and you need to remove other taxonomy terms using jQuery or Javascript.
If you can share problem URL and access details I can try to fit it for you.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Well - I'm about the provide you solution but on your test site I'm seeing now 502 page not found errors. Page is not properly loading.
Hi Minesh,
thanks a lot for your help.
it must have been an accidental problem. I can access the website and navigate through posts.
can you please recheck?
thanks.
could you please check now.
I've added following code to your current theme's functions.php file:
add_filter( 'wpv_filter_query', 'filter_post_type_func', 99, 3 ); function filter_post_type_func( $query_args, $view_settings, $view_id ) { global $WP_Views; $view_ids_array = array(16553); if ( in_array($view_id, $view_ids_array) ) { if(!isset($_GET['wpv-category'])){ if(isset($WP_Views->view_shortcode_attributes[0]['wpvcategory'])){ $category = strtr($WP_Views->view_shortcode_attributes[0]['wpvcategory'], ' ', ''); $category = explode(',', $category); $query_args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => $category, 'operator' => 'IN', ); $query_args['tax_query']['relation'] = 'AND'; } } } return $query_args; }
I've added following code to your view's filter section JS box:
jQuery(document).ready(function($){ terms = ['music','arts'] $('div.radio .js-wpv-filter-trigger').each(function() { if(jQuery.inArray($(this).val() , terms ) != '-1'){ $(this).closest("div").show(); }else{ $(this).closest("div").remove(); } }); });
I've added following code to your view's filter section CSS box:
div.radio { display: none; }
And I've added your view and passed taxonomy terms slug as view's shortcode attribute as given under:
[wpv-view name="music and art view" wpvcategory="arts,music"]
Could you please verify and confirm its resolved now.
Also, regarding your another question, please contact the dedicated supporter of that ticket.
Hi Minesh,
thanks a lot. the code is working. I really can't thank you enough.
just 2 points, please:
1- is there a way to show a button saying "All", in case the user wants to get out of the filtering?
2- as for the "other question", i can't contact the dedicated supporter, because he already told me that there is no way to specify parameters in the custom search shortcode. but you told me that I can do so, so I am asking you how to do it. He does not believe that it can be done.
can you please put me in the correct direction ?
thanks a lot.
1- is there a way to show a button saying "All", in case the user wants to get out of the filtering?
==> Sure - I've added following button for "ALL" and I checked it works as expected.
<input action="action" onclick="window.location.href=window.location.origin+'/'+location.pathname.substring(1)" type="button" value="ALL">
2- as for the "other question", i can't contact the dedicated supporter, because he already told me that there is no way to specify parameters in the custom search shortcode. but you told me that I can do so, so I am asking you how to do it. He does not believe that it can be done.
can you please put me in the correct direction ?
===> Well - by default its not supported as you can see with this ticket as well, you need to add few filters using the custom code like we added 'wpv_filter_query' filter to implement functionality for this support request.
It also depends upon what kind of functionality you want and its feasible to implement using Toolset if it comes within the Toolset support policy.
I request you to open a new ticket for your each new question and link your old ticket for reference.