Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function filter_cursos(){
- $ret = new StdClass();
- $ret->success = false;
- if( !isset($_POST['s']) || !isset($_POST['cats']) || !isset($_POST['location']) ){
- //error
- //TODO BOTAR HTML DE ERRO BONITINHO
- do_json($ret);
- exit;
- }
- $args = [
- 'suppress_filters' => false,
- 'fields' => 'ids',
- 'numberposts' => get_option( 'posts_per_page' ),
- 'offset' => get_option( 'posts_per_page' ) * $_POST['offset'],
- 'post_type' => 'curso',
- ];
- if( !(empty($_POST['s']) ) ){
- $args += [
- 's' => $_POST['s'] ,
- ]; //Se tem filtro adicionamos os campos para filtrar por busca
- }
- if(! empty($_POST['cats']) ){
- $args += ['category__in' => (!empty($_POST['cats'])) ? explode(',', $_POST['cats']) : [],];
- }
- if(!empty($_POST['location'])){
- $args += [ //added locais de turmas
- 'meta_query' => array(
- 'relation' => 'OR',
- array(
- 'key' => 'datas_%_localizacao',
- 'compare' => 'IN',
- 'value' => (!empty($_POST['location'])) ? explode(',', $_POST['location']) : [],
- )
- ),//end meta_query
- ];
- }
- //tratando os titulos
- if(!empty($_POST['s'])){
- $ret->title = 'Course search results for <strong>"'.$_POST['s'].'"</strong>';
- }elseif(!empty($_POST['cats']) && empty($_POST['location'])){
- $ret->title = 'Course search results by <strong>Competency</strong>';
- }elseif(!empty($_POST['location']) && empty($_POST['cats'])){
- $ret->title = 'Course search results by <strong>Location</strong>';
- }elseif( !empty($_POST['cats']) && !empty($_POST['location']) ){
- $ret->title = 'Course search results by <strong>Competency and Location</strong>';
- }else{
- $ret->title = 'Recent <ewrwerstrong>Learning Experiences</strong>';
- }
- $cursos = get_posts($args);
- ob_start();
- foreach($cursos as $post_id):
- include TEMPLATEPATH.'/bloco-curso.php';
- endforeach;
- $ret->html = ob_get_clean();
- if (empty($cursos)) {
- $ret->title = 'Your search did not match any of the above.';
- }
- $ret->success = true;
- do_json($ret);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement