Skip to content

Instantly share code, notes, and snippets.

@Bobz-zg
Created August 25, 2016 09:55
Show Gist options
  • Save Bobz-zg/87b4e5f02a3d8695e0900785ac3f9231 to your computer and use it in GitHub Desktop.
Save Bobz-zg/87b4e5f02a3d8695e0900785ac3f9231 to your computer and use it in GitHub Desktop.
Filter WordPress posts by custom taxonomy term with AJAX
$('#container-async').on('click', 'a[data-filter], .pagination a', function(event) {
if(event.preventDefault) { event.preventDefault(); }
$this = $(this);
if ($this.data('filter')) {
/**
* Click on tag cloud
*/
$this.closest('ul').find('.active').removeClass('active');
$this.parent('li').addClass('active');
$page = $this.data('page');
}
else {
/**
* Click on pagination
*/
$page = parseInt($this.attr('href').replace(/\D/g,''));
$this = $('.nav-filter .active a');
}
$params = {
'page' : $page,
'tax' : $this.data('filter'),
'term' : $this.data('term'),
'qty' : $this.closest('#container-async').data('paged'),
};
// Run query
get_posts($params);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment