Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //filtrar edital
- add_action('wp_ajax_myfilter', 'filter_edital'); // wp_ajax_{ACTION HERE}
- add_action('wp_ajax_nopriv_myfilter', 'filter_edital');
- function filter_edital() {
- // Inicializando
- $meta_query_args = [ 'relation' => 'AND' ];
- // Filtro de Estado
- if ( ! empty( $_POST['estado_filter'] ) ) {
- console_log("estado");
- $meta_query_args[] = array(
- 'meta_key' => 'estados_brasil',
- 'meta_value' => sanitize_text_field( $_POST['estado_filter']),
- 'compare' => '='
- );
- }
- // Filtro de Cidade
- if ( ! empty( $_POST['cidade_filter'] ) ) {
- console_log("cidade");
- $meta_query_args[] = array(
- 'meta_key' => 'cidade_',
- 'meta_value' => sanitize_text_field( $_POST['cidade_filter']),
- 'compare' => '='
- );
- }
- // Argumentos
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => -1,
- 'order' => 'ASC',
- );
- if ( count( $meta_query_args ) > 1 ) {
- $args['meta_query'] = $meta_query_args;
- }
- // A Query
- $query = new WP_Query( $args );
- if ( $query->have_posts() ) :
- while( $query->have_posts() ): $query->the_post();
- echo '<h2 class="h1"><a class="post-default__link" href="'.get_the_permalink().'">'.get_the_title().'</a></h2>';
- endwhile;
- wp_reset_postdata();
- else :
- echo '<h1> Nenhuma notΓcia encontrada </h1>';
- endif;
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement