Problem: I would like to add a filter to my custom search View that has options with different price ranges. For example, Less than 50, 50 - 100, and 100+.
Solution: There is not an easy way to accomplish this in Toolset using a standard price filter. You would have to create a separate custom field that holds a value that represents each price range, then filter based on that custom field. To automate the process, you could use a hook like save_post or pmxi_saved_post to check the current price and update the value automatically:
function post_saved( $post_id, $post, $update ) { $range = 0; $price = get_post_meta( $post_id, 'wpcf-price', true); if( $price < 50000 ) { $range = 1; }else if( $price >= 50000 && $price <= 100000 ) { $range = 2; } else if( $price > 100000 ) { $range = 3; } update_post_meta( $post_id, 'wpcf-sort-price', $range); } add_action( 'pmxi_saved_post', 'post_saved',10,1);
Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
https://codex.wordpress.org/Function_Reference/update_post_meta
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 2 voices.
Last updated by 6 years, 5 months ago.
Assisted by: Christian Cox.