Created
August 12, 2016 16:03
-
-
Save Bobz-zg/16578c3c173abfe2b22daffd67f6f1e0 to your computer and use it in GitHub Desktop.
Filter WP posts by tag - JS
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
jQuery(document).ready(function($) { | |
$('.tax-filter').click( function(event) { | |
// Prevent default action - opening tag page | |
if (event.preventDefault) { | |
event.preventDefault(); | |
} else { | |
event.returnValue = false; | |
} | |
// Get tag slug from title attirbute | |
var selecetd_taxonomy = $(this).attr('title'); | |
// After user click on tag, fade out list of posts | |
$('.tagged-posts').fadeOut(); | |
data = { | |
action: 'filter_posts', // function to execute | |
afp_nonce: afp_vars.afp_nonce, // wp_nonce | |
taxonomy: selecetd_taxonomy, // selected tag | |
}; | |
$.post( afp_vars.afp_ajax_url, data, function(response) { | |
if( response ) { | |
// Display posts on page | |
$('.tagged-posts').html( response ); | |
// Restore div visibility | |
$('.tagged-posts').fadeIn(); | |
}; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment