Home › Forums › Pro Support › WPSP Custom Ajax request › Reply To: WPSP Custom Ajax request
May 24, 2019 at 6:08 pm
#9530
Keymaster
Here’s one way you might be able to achieve something like this.
Add the following functions:
add_action( 'wpsp_inside_wrapper', function( $settings ) {
if ( count( $settings[ 'tax_term' ] ) > 0 ) {
echo '<select class="drop-filter"><option value="all">All</option>';
$cnt = sort( $settings[ 'tax_term' ] );
foreach ( $settings[ 'tax_term' ] as $trm ) {
echo '<option value="' . $trm . '">' . str_replace( '-',' ',$trm ) . '</option>';
}
echo '</select>';
}
} );
add_action( 'wp_footer', function() {
?>
jQuery( document ).ready( function( $ ) {
$( ".drop-filter" ).change( function() {
var selectedOption = $( this ).children( "option:selected" ).val();
if ( 'all' === selectedOption ) {
$( '.wp-show-posts-single' ).fadeIn( 100 );
} else {
$( '.wp-show-posts-single' ).fadeOut( 100 );
$( '.location-' + selectedOption ).fadeIn( 100 );
}
} );
});
<?php
} );
The only change you need to make is this line:
$( '.location-' + selectedOption ).fadeIn( 100 );
location
is the taxonomy – so you’d need to update that with whatever taxonomy slug you’re using.