Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement