-3

Basically I have newsletter.php page where all the existing custom post are display. from here, I have a dropdown category lists which you can filter the custom post by its category. once you click the specific category, it will proceed to pdf_cat.php to display the filtered output. the problem is the result page item doesn't show up. can you help me to figure it out the logic here? here are my code so far:

from newsletter.php --> dropdown category button:

<select name="form" id="form">
   <div class="options">
      <option value="<?php echo home_url('/newsletter'); ?>" selected>一覧</option>                                   
         <?php
            $args = array(
             'orderby' => 'slug',
             'order' => 'ASC',
             'parent' => 0,
             'hide_empty' => false
            );
             $terms = get_terms([
              'taxonomy' => 'pdf_cat',
              'hide_empty' => false,
             ]);
               foreach( $terms as $term ){
                  echo '<option class="ctg" value="'. get_term_link($term->term_id) .' ">' . $term->name . '</option>';                                                

            }
         ?>   
     </div>   
   </select>

My JS to fire the url link:

   <script type="text/javascript">
      $("#form").change(function(){
      var url = $(this).val();
      location.assign(url);
      });
   </script>

My pdf_cat.php page where the filtered result supposed to display:

  <?php
    $terms = get_the_terms();                    // get the category from query
    $terms = $term[0];                                        
    $term_name = get_term_name($term->name);     // get the category name
    $term_id = get_term_ID($term->term_id);      // get the catehory ID
  ?>
      
  <?php
    $paged = get_query_var('paged', 1);
    $args = array(                          // asigned the functions inside the array
      'paged' => $paged,
      'post_type' => 'pdf',
      'taxonomy' => $term_id,
      );
    $query = new WP_Query($args);          // get the functions inside the assigned name 
             
      global $query_string; //Post the specify numbers per page
      query_posts( $query_string . "&posts_per_page=12&paged=".$paged );
      while ( have_posts() ) : the_post()
    ?>

Can anyone help me to fixed this issue? I hope this time I explain it clearly.

maru
  • 35
  • 7
  • var url = $(this).val(); here, can you please try to print the url value to the console and is that the correct value? and in pdf_cat.php where are you receiving the category value? – user703894 Dec 20 '21 at 06:51
  • hi @user703894 I'm sorry my first time to use this var url = $(this).val(); how to use this code? – maru Dec 20 '21 at 08:00
  • yes on pdf_cat.php is my receiving category value – maru Dec 20 '21 at 08:01
  • I put the var url = $(this).val(); on script and nothing happened. here is the link page I am working on. https://wptest.porowakka.co.jp/new/newsletter/ please check and let me know your thoughts. – maru Dec 20 '21 at 08:05
  • I am still trying to figure it out through different code that relevant to custom taxonomy but still I am redirecting to the top page when clicked the category, even the taxonomy URL LINK is correct. anyone please help – maru Dec 20 '21 at 12:43

1 Answers1

1

You just need to change your pdf_cat.php to taxonomy.php and allow wordpress to open the taxonomy id link for you^^

check this link https://wphierarchy.com/

Marvin Acosta
  • 168
  • 10
  • hi @Marvin Acosta thank you so much for this information ^^ I been trying this for 1 week and looking for the answer, I didn't even know that there is a default. and I think some of here didn't know about it. thank you so much you are a big help. – maru Dec 22 '21 at 07:57