Created
September 29, 2019 09:25
-
-
Save Bobz-zg/ec99843d687f6af7c947b0e378e8beaa to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Setup query | |
*/ | |
// Move this on top | |
$args = [ | |
'paged' => $page, | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'posts_per_page' => $qty, | |
]; | |
/** | |
* Check if term exists | |
*/ | |
// Check if there are any terms specified, if not don't add any | |
if ( $term && $tax ) : | |
if ( ! term_exists( $term, $tax) && $term != 'all-terms' ) : | |
$response = [ | |
'status' => 501, | |
'message' => 'Term doesn\'t exist', | |
'content' => 0 | |
]; | |
die(json_encode($response)); | |
endif; | |
/** | |
* Tax query | |
*/ | |
if ($term == 'all-terms') : | |
$tax_qry[] = [ | |
'taxonomy' => $tax, | |
'field' => 'slug', | |
'terms' => $term, | |
'operator' => 'NOT IN' | |
]; | |
else : | |
$tax_qry[] = [ | |
'taxonomy' => $tax, | |
'field' => 'slug', | |
'terms' => $term, | |
]; | |
endif; | |
$args['tax_query'] => $tax_qry; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment