How to query custom post types posts filtered by multiple custom taxonomies through a form selection

I’m trying to create a sort of selection menu, in order to select custom posts by different custom taxonomies. I did the selection part, but I can’t get to output my post and I can’t understand where my mistakes are.
What I have so fare:
– Custom post type: “corsi”;
– 5 different custom taxonomies: “prodotto”, “livello”, “ruolo”, “stato”;
– The selection form, made as a form, with radio button input and a bit of jQuery.

The form part

<form id=”regiration_form” novalidate action=”<?php echo $current_url;?>” method=”post”>
<fieldset>
<div class=”form-group”>
<h1>1</h1>
<?php

$prodotto_terms = get_terms( ‘prodotto’, array(
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘hide_empty’ => 0
) );
?>
<?php foreach( $prodotto_terms as $term ) {
$term_link = get_term_link( $term );
echo ‘<input type=”radio” name=”prodotto” value=”‘.$term->slug.'”>’.$term->name.'<br>’;
}

?>

</div>
<input type=”button” name=”next” class=”next btn btn-info” value=”Next” />
</fieldset>
<fieldset>
<div class=”form-group”>
<h1>2</h1>
<?php $livello_terms = get_terms( ‘livello’, array(
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘hide_empty’ => 0
) );
?>
<?php foreach( $livello_terms as $term ) {
$term_link = get_term_link( $term );
echo ‘<input type=”radio” name=”livello” value=”‘.$term->slug.'”>’.$term->name.'<br>’;
}

?>

<?php $ruolo_terms = get_terms( ‘ruolo’, array(
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘hide_empty’ => 0
) );
?>
</div>
<input type=”button” name=”previous” class=”previous btn btn-default” value=”Previous” />
<input type=”button” name=”next” class=”next btn btn-info” value=”Next” />
</fieldset>
<fieldset>
<div class=”form-group”>
<h1>3</h1>
<?php foreach( $ruolo_terms as $term ) {
$term_link = get_term_link( $term );
echo ‘<input type=”radio” name=”ruolo” value=”‘.$term->slug.'”>’.$term->name.'<br>’;
}

?>

<?php $stato_terms = get_terms( ‘stato’, array(
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘hide_empty’ => 0
) );
?>
</div>
<input type=”button” name=”previous” class=”previous btn btn-default” value=”Previous” />
<input type=”button” name=”next” class=”next btn btn-info” value=”Next” />
</fieldset>

<fieldset>
<div class=”form-group”>
<h1>4</h1>
<?php foreach( $stato_terms as $term ) {
$term_link = get_term_link( $term );
echo ‘<input type=”radio” name=”stato” value=”‘.$term->slug.'”>’.$term->name.'<br>’;
}

?>

</div>
<input type=”button” name=”previous” class=”previous btn btn-default” value=”Previous” />
<input type=”submit” name=”submit” class=”submit btn btn-success” value=”Submit” />
</fieldset>
</form>

And this how I tried to output the posts, but nothing is showing up :/

<?php
if(isset($_REQUEST[‘submit’]))
{

$prodotto = $_POST[“prodotto”];
$livello = $_POST[“livello”];
$ruolo = $_POST[“ruolo”];
$stato = $_POST[“stato”];

$soluzioni = new WP_Query( array(
‘post_type’ => ‘corsi’,
‘posts_per_page’ => -1,
‘orderby’ => ‘title’,
‘order’ => ‘ASC’,
‘paged’ => $paged,
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘prodotto’,
‘field’ => ‘slug’,
‘terms’ => $prodotto
),
array(
‘taxonomy’ => ‘livello’,
‘field’ => ‘slug’,
‘terms’ => $livello
)
) ) );

if ( $soluzioni->have_posts() ) {
echo ‘<ul>’;
while ( $soluzioni->have_posts() ) {
$soluzioni->the_post();
echo ‘<li>’ . get_the_title() . ‘</li>’;
}
echo ‘</ul>’;

wp_reset_postdata();
} else {
// no posts found
}

} ?>

What am I doing wrong?

Thanks in advance, have a nice day 🙂

Lisa

Read more here:: How to query custom post types posts filtered by multiple custom taxonomies through a form selection

Leave a Reply

Your email address will not be published. Required fields are marked *