Entonces, esta es una pregunta larga, por lo que le damos un ejemplo simple que funcionará para
Paso 1) Cat1 cat2 cat3
para esto primero debe llamar taxonomía personalizada en un formulario
Paso 2) Suponga que tiene cat1 cat2 como una casilla de verificación con el valor de la identificación de taxonomía personalizada
Paso 3) Agrega un evento de clic
Paso 4) Llama a tu función ajax
Vaya a este ejemplo - enlace : espero que desee lograr este clic en las casillas de verificación son taxonomía personalizada y al hacer clic en la clasificación de filtros de acuerdo a la taxonomía.
Método - comencemos: -
Esta es la plantilla de salida page_lat.php:
Resultados de la búsqueda (actualmente solo imprime título y tipo de publicación:
<?php
if($_GET['s'] && !empty($_GET['s'])){
$text =$_GET['s'];
$posttype = $_GET['post_type'];
}
else{
$posttype = 'custom_post_type';
}
?>
//This will fetch your custom taxonomy cat1, cat2 , cat3
<form action="" method="" class="" id="filter-menu" >
<?php
$terms = get_terms('post_tag',, array('hide_empty' => false) );
foreach($terms as $filteroption)
{
<input type="checkbox" name="filter[]" value="<?php echo $filteroption->term_id; ?>" onclick="filtermenu()" >
<?php echo $filteroption->name; ?>
}
<input type="hidden" name="posttype" id="posttype" value="<?php echo $posttype; ?>" />
?>
<form>
<div class="container">
<div class="load_html">
<?php
$args = array(
'post_per_page'=> -1,
's'=>$text
);
$query= new WP_Query($args);
while($query->have_posts()): $query->the_post();
?>
<div>
<h5><?php the_title(); ?></h5>
<strong>
<?php echo get_post_type(); ?>
</strong>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
Agregar clic al evento haciendo clic
<script> //this a click event of checkbox which call ajax action
function filtermenu(paged)
{
var filtercheckedbox = // get your checkbox value via jquery;
var posttype = // get your posttype value; jQuery('#posttype').val(0);
jQuery.ajax({
url: AJAXURL,
data: {
'action' : 'filter_menu' ,
'checkbox': filtercheckedbox,
'posttype' :posttype,
'paged' : 1,
},
type: 'POST',
success: function(data) {
jQuery(".load_html").html(data);
}
});
}
</script>
Añade tu acción a functions.php
<?php
// add this function to functions.php this is your ajax action
add_action( 'wp_ajax_filter_menu', 'wp_ajax_filter_menu' );
add_action( 'wp_ajax_nopriv_filter_menu', 'wp_ajax_filter_menu' );
function wp_ajax_filter_menu()
{
global $post, $wp_query;
$args = array(
'post_type' => '$_POST['post_type']',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'custom_taxonomy name',
'field' => 'term_id',
'terms' => array($_POST['checkbox']),
),
),
'orderby' => 'ASC',
);
$filteroption = new WP_Query( $args );
if ( $filteroption->have_posts() ) :
while ($filteroption->have_posts()) : $filteroption->the_post();
?>
<div>
<h5><?php the_title(); ?></h5>
</div>
<?php
endwhile;
else:
return false;
endif;
}
die;
}
?>