admin管理员组

文章数量:1279112

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>

本文标签: categoriesCustom post type archive page filters