Skip to content

Instantly share code, notes, and snippets.

@rodrigophpweb
Created January 8, 2019 14:29
Show Gist options
  • Save rodrigophpweb/b1ebdcc0849cb7c53a32219752fe3276 to your computer and use it in GitHub Desktop.
Save rodrigophpweb/b1ebdcc0849cb7c53a32219752fe3276 to your computer and use it in GitHub Desktop.
// Chamando Requisição Ajax
add_action('wp_ajax_myfilter', 'filters_function');
add_action('wp_ajax_nopriv_myfilter', 'filters_function');
function filters_function(){
// Para chamar CPT empresa
$args = array(
'post_type' => 'empresa',
'orderby' => 'title',
'order' => 'ASC'
);
// Loop para pegar os valores dos Checkboxs selecionados e jogar na Meta Query
$atuacao = $_POST['atuacao'];
foreach( $atuacao as $post ){
$args['meta_query'][] = array(
'key' => 'produtos_e_servicos',
'value' => $post,
'compare' => '='
);
}
$categorias = $_POST['categoria'];
foreach($categoria as $resultado ){
$args['meta_query'][] = array(
'key' => 'categorias',
'value' => $resultado,
'compare' => '='
);
}
// Montando a Query
$query = new WP_Query($args);
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
echo
'
<div class="col-lg-4">
<figure>
<a href="'. $query->post->get_post_field('site') .'" target="_blank">
<img src="' . $query->post->get_post_field('marca') .'">
</a>
<figcaption>'. $query->post->post_title .'</figcaption>
</figure>
</div>';
endwhile;
wp_reset_postdata();
else :
echo 'No posts found';
endif;
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment