Problem:
The issue here is that the user wanted to filter their posts by a range of numbers using one filter.
Example
1970-1980
1980-1990
1990-2000
So we will have a filter that allows for the filtering of dates between those options.
Solution:
So you will need to add the filter for the custom field to your view but instead of setting that filter to load from the database we are going to add our custom values. So your filter should be generated like the following below.
Example
<div class="form-group"> <label>[wpml-string context="wpv-views"]Number of pages[/wpml-string]</label> [wpv-control-postmeta field="wpcf-active-year" type="select" source="custom" url_param="wpv-wpcf-active-year" values="1970-1980,1980-1990,1990-2000" display_values="1970-1980, 1980-1990,1990-2000"] </div>
If your custom field is already stored like this then you won't need to go through all this above, however i'm assuming that the values are stored as individual years.
Ofcourse for this to work you will need to use the hook below. Granted this will only work if you are not using the AJAX reload.
add_filter('wpv_filter_query', 'search_between_numeric_func', 10, 3); function search_between_numeric_func($query, $views_setting,$view_id) { if($view_id == '614' && isset($_GET['wpv-wpcf-active-year'])) { $val = $_GET['wpv-wpcf-active-year']; $query['meta_query']= array( array( 'key' => 'wpcf-active-year', 'value' => explode("-",$val), 'type' => 'numeric', 'compare' => 'BETWEEN', ), ); } return $query; }
Now everywhere you see me have wpcf-active-year you will need to replace it with the custom field slug, using the wpcf- as a prefix to the slug.
From the filter fields and the hook you can see how the items line up. The wpv-wpcf-active-year is a direct reference to the url parameter for the filter shortcode.
Also you need to replace the 614 with your correct view ID.
You can add this custom hook to your Toolset custom code in Toolset->Settings->Custom code.
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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
Ce sujet contient 2 réponses, a 2 voix.
Dernière mise à jour par Il y a 5 années et 7 mois.
Assisté par: Shane.