Advertisement
Guest User

Untitled

a guest
Nov 1st, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.52 KB | None | 0 0
  1. <?php
  2.  
  3. //filtrar
  4. add_action('wp_ajax_myfilter', 'filter_news'); // wp_ajax_{ACTION HERE}
  5. add_action('wp_ajax_nopriv_myfilter', 'filter_news');
  6.  
  7. function filter_news() {  
  8.     // $args = array(
  9.     //     'post_type' => 'post',
  10.     //     'posts_per_page' => -1 ,  
  11.     //     'orderby' => 'date', // we will sort posts by date
  12.     //     'order'  => $_POST['date'], // ASC or DESC
  13.     //     'fields' => 'ids',            
  14.     // );
  15.  
  16.  
  17.     $args1 = array(  
  18.         'fields' => 'ids',          
  19.         'tax_query' => array(                
  20.            array(              
  21.             'taxonomy' => 'category',
  22.             'field' => 'id',
  23.             'terms' => $_POST['areafilter'],
  24.            ),
  25.         ),
  26.     );
  27.  
  28.     $query1 = new WP_Query( $args1 );
  29.  
  30.     $args2 = array(
  31.         'fields' => 'ids',
  32.         'tax_query' => array(
  33.         array(              
  34.             'taxonomy' => 'post_tag',
  35.             'field' => 'id',
  36.             'terms' => $_POST['assuntofilter'],
  37.            ),            
  38.         ),
  39.     );
  40.  
  41.     $query2 = new WP_Query( $args2 );
  42.  
  43.     $args3 = array(
  44.         'fields' => 'ids',      
  45.         'date_query' => array(
  46.             array(
  47.                'key' => 'mes',                            
  48.                'month' => $_POST['mesfilter'],
  49.             ),              
  50.         ),
  51.      
  52.     );
  53.    
  54.     $query3 = new WP_Query( $args3 );
  55.    
  56.     $args4 = array(
  57.         'fields' => 'ids',  
  58.         'date_query' => array(            
  59.             array(  
  60.                 //  'relation' => 'OR',
  61.                 'key' => 'ano',                
  62.                 'year' => $_POST['anofilter'],
  63.              ),
  64.         ),
  65.      
  66.     );
  67.  
  68.     $query4 = new WP_Query( $args4 );
  69.  
  70.     $all_IDs = array_merge( $query4->posts );
  71.    
  72.    
  73.     $final_query = new WP_Query( array( 'post__in' => $all_IDs ) );
  74.  
  75.  
  76.     if (  $final_query->have_posts() ) :
  77.         while( $final_query->have_posts() ):  $final_query->the_post();
  78.            
  79.            echo '<article id="post-'. $final_query->post->ID.'"  class="post-default ajax"> ';
  80.            echo '<a href="'.get_the_permalink().'">';      
  81.            echo '<img src="'.get_the_post_thumbnail_url().'" />';
  82.            echo '</a>';
  83.            echo '<div class="post-default__meta post-meta">';
  84.                     echo'<div class="post-meta__column">';
  85.                          echo'<span class="post-meta__date">'.get_the_date().'</span>';
  86.                     echo'</div>';                    
  87.             echo'</div>';
  88.             echo '<h2 class="h1"><a href="'.get_the_permalink().'">'.get_the_title().'</a></h2>';
  89.             echo '<p>'.the_excerpt().'</p>';
  90.             echo '<div class="post-default__footer post-footer">
  91.                    <div class="post-footer__column" style="width: 42% !important;"> Área:';
  92.             echo      '<p><span>'.the_category('Assunto:', '<br />').'</span>
  93.                       <span> '.the_tags( ' / Assunto: ', '<br />').'</span></p>';
  94.             echo       '<a href="'.get_the_permalink().'">saiba mais</a>
  95.                    </div>';
  96.             echo    '<div class="post-footer__column">
  97.                       <span class="post-footer__comments">'.comments_number( '(0) Comentários', '(1) Comentário', '(%) Comentários' ).'</span>
  98.                    </div>';  
  99.            echo '</article>';
  100.            
  101.         endwhile;
  102.        
  103.         wp_reset_postdata();
  104.        
  105.     else :
  106.         echo '<h1> Nenhuma notícia encontrada </h1>';
  107.     endif;
  108.  
  109.     die();
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement