Skip to content

Instantly share code, notes, and snippets.

@Bobz-zg
Created September 29, 2019 09:25
Show Gist options
  • Save Bobz-zg/ec99843d687f6af7c947b0e378e8beaa to your computer and use it in GitHub Desktop.
Save Bobz-zg/ec99843d687f6af7c947b0e378e8beaa to your computer and use it in GitHub Desktop.
<?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