Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. function filter_cursos(){
  2. $ret = new StdClass();
  3. $ret->success = false;
  4.  
  5. if( !isset($_POST['s']) || !isset($_POST['cats']) || !isset($_POST['location']) ){
  6. //error
  7. //TODO BOTAR HTML DE ERRO BONITINHO
  8. do_json($ret);
  9. exit;
  10. }
  11.  
  12. $args = [
  13. 'suppress_filters' => false,
  14. 'fields' => 'ids',
  15. 'numberposts' => get_option( 'posts_per_page' ),
  16. 'offset' => get_option( 'posts_per_page' ) * $_POST['offset'],
  17. 'post_type' => 'curso',
  18. ];
  19.  
  20.  
  21. if( !(empty($_POST['s']) ) ){
  22. $args += [
  23. 's' => $_POST['s'] ,
  24. ]; //Se tem filtro adicionamos os campos para filtrar por busca
  25. }
  26. if(! empty($_POST['cats']) ){
  27. $args += ['category__in' => (!empty($_POST['cats'])) ? explode(',', $_POST['cats']) : [],];
  28.  
  29. }
  30. if(!empty($_POST['location'])){
  31. $args += [ //added locais de turmas
  32. 'meta_query' => array(
  33. 'relation' => 'OR',
  34. array(
  35. 'key' => 'datas_%_localizacao',
  36. 'compare' => 'IN',
  37. 'value' => (!empty($_POST['location'])) ? explode(',', $_POST['location']) : [],
  38. )
  39. ),//end meta_query
  40. ];
  41. }
  42. //tratando os titulos
  43. if(!empty($_POST['s'])){
  44. $ret->title = 'Course search results for <strong>"'.$_POST['s'].'"</strong>';
  45.  
  46. }elseif(!empty($_POST['cats']) && empty($_POST['location'])){
  47.  
  48. $ret->title = 'Course search results by <strong>Competency</strong>';
  49. }elseif(!empty($_POST['location']) && empty($_POST['cats'])){
  50.  
  51. $ret->title = 'Course search results by <strong>Location</strong>';
  52. }elseif( !empty($_POST['cats']) && !empty($_POST['location']) ){
  53.  
  54. $ret->title = 'Course search results by <strong>Competency and Location</strong>';
  55. }else{
  56. $ret->title = 'Recent <ewrwerstrong>Learning Experiences</strong>';
  57. }
  58.  
  59. $cursos = get_posts($args);
  60. ob_start();
  61. foreach($cursos as $post_id):
  62.  
  63. include TEMPLATEPATH.'/bloco-curso.php';
  64.  
  65. endforeach;
  66. $ret->html = ob_get_clean();
  67. if (empty($cursos)) {
  68. $ret->title = 'Your search did not match any of the above.';
  69. }
  70.  
  71. $ret->success = true;
  72. do_json($ret);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement