-
-
Save dexit/f6d0fa834aa9737ff73a43101a3d0c9e to your computer and use it in GitHub Desktop.
ACF Repeater Fields - Filter by Price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($){ | |
| $(function(){ | |
| $(document.body).on( 'change', '#min_price, #max_price', function(){ | |
| var minPrice = parseFloat( $('#min_price').val() ); | |
| var maxPrice = parseFloat( $('#max_price').val() ); | |
| $('.item-list li').each(function(){ | |
| var price = parseFloat( $(this).attr('data-price') ); | |
| var hide = false; | |
| if ( minPrice && price < minPrice ) { hide = true; } | |
| if ( maxPrice && price > maxPrice ) { hide = true; } | |
| if ( hide ) { | |
| $(this).hide(); | |
| } else { | |
| $(this).show(); | |
| } | |
| }); | |
| }); | |
| }); | |
| })(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $repeater_values = get_field( 'repeater_field_key', $post_id ); | |
| ?> | |
| <input type="number" value="0" placeholder="Min Price" id="min_price" /> | |
| <input type="number" value="10000" placeholder="Max Price" id="max_price" /> | |
| <ul class="item-list"> | |
| foreach ( $repeater_values as $repeat_item ) { | |
| ?> | |
| <li data-price="<?php echo esc_attr( $repeat_item['price'] );?>"> | |
| <?php echo $repeat_item['title']; ?> | |
| </li> | |
| <?php | |
| } | |
| ?> | |
| </ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment