Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5. * Setup query
  6. */
  7. // Move this on top
  8. $args = [
  9. 'paged' => $page,
  10. 'post_type' => 'post',
  11. 'post_status' => 'publish',
  12. 'posts_per_page' => $qty,
  13. ];
  14.  
  15. /**
  16. * Check if term exists
  17. */
  18. // Check if there are any terms specified, if not don't add any
  19. if ( $term && $tax ) :
  20.  
  21. if ( ! term_exists( $term, $tax) && $term != 'all-terms' ) :
  22. $response = [
  23. 'status' => 501,
  24. 'message' => 'Term doesn\'t exist',
  25. 'content' => 0
  26. ];
  27. die(json_encode($response));
  28. endif;
  29. /**
  30. * Tax query
  31. */
  32. if ($term == 'all-terms') :
  33. $tax_qry[] = [
  34. 'taxonomy' => $tax,
  35. 'field' => 'slug',
  36. 'terms' => $term,
  37. 'operator' => 'NOT IN'
  38. ];
  39. else :
  40. $tax_qry[] = [
  41. 'taxonomy' => $tax,
  42. 'field' => 'slug',
  43. 'terms' => $term,
  44. ];
  45. endif;
  46.  
  47. $args['tax_query'] => $tax_qry;
  48.  
  49. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement