0

What is the proper way to filter my custom post type archive page by my custom taxonomies? When i go to archive page(archive-recipies.php), fetch me all the post under the custom post type. In this page archive-recipies.php i made one form with two select inputs filled with my custom taxonomies! I want when form submited to filter depent what user select! This the code!

    <form method="GET">
        <div class="row py-5">
            <div class="col-4">
                <select class="form-select" name="band">
                    <option value="" selected="true" disabled="disabled">Select band</option>
                    <?php
                    $tax_terms= get_terms('bands', array('hide_empty' => '0', 'parent' => '0'));
                            foreach ( $tax_terms as $tax_term ):
                                echo '<option value="'.$tax_term->term_id.'">'.$tax_term->name.'</option>';   
                            endforeach;
                    ?>
                </select>
            </div>
             <div class="col-4">
                <select class="form-select" name="country">
                    <option value="" selected="true" disabled="disabled">Select country</option>
                     <?php 
                        $tax_terms= get_terms('countries', array('hide_empty' => '0', 'parent' => '0'));
                        foreach ( $tax_terms as $tax_term ): 
                            $email = get_field('acf_taxonomy_email', $tax_term);
                            echo '<option value="'.$tax_term->term_id.'">'.$tax_term->name.'</option>';   
                        endforeach;
                     ?>
                </select>   
            </div>
             <div class="col-4">
                <button type="submit" class="btn btn-success">Success</button>
            </div>
        </div>
    </form>

   <table class="table">
     <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">Name</th>
          <th scope="col">Email</th>
          <th scope="col">Band</th>
          <th scope="col">Countries</th>
          <th scope="col">Favorite song</th>
        </tr>
    <tbody>  
   <?php if ( have_posts() ) :
    $i = 1;
    while ( have_posts() ) : the_post(); ?>
        <tr>
          <th scope="row"><?php echo $i ?></th>
          <td><?php the_title() ?></td>
          <td><?php echo get_post_meta(get_the_ID(), 'acf_email_live', true); ?></td>
          <td>
              <?php
                $tax_terms = the_terms( get_the_ID(), 'bands' );
                foreach ( $tax_terms as $tax_term ) :
                   echo $tax_term->name; 
                endforeach
              ?>
          </td>
          <td>
            <?php
                $tax_terms = the_terms( get_the_ID(), 'countries' );
                foreach ( $tax_terms as $tax_term ) :
                   echo '<p>'.$tax_term->name.'</p>';
                endforeach
              ?>
          </td>
          <td><?php the_content(); ?></td>
       </tr>
      
<?php  $i++;
    endwhile; 
    endif; ?>
     </tbody>
</table>
4
  • 1
    Please add more detail (code) to show what you have done already.
    – cjbj
    Oct 20 at 17:09
  • I made the archive-{slug}.php. in this file i have if have_posts while_have_posts loop and fetch all tha data in one table! I made one form whith two taxonomies select inputs and i want when user submit the form to saw the posts result depent what user has submit! Oct 20 at 18:26
  • You'll need to paste the contents of your archive-slug.php in the question for folks to be able to help.
    – WebElaine
    Oct 20 at 18:27
  • I want when the form submit to change the query! Oct 20 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.