Created
August 25, 2016 09:55
-
-
Save Bobz-zg/87b4e5f02a3d8695e0900785ac3f9231 to your computer and use it in GitHub Desktop.
Filter WordPress posts by custom taxonomy term with AJAX
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
$('#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