0

Still trying to figure it out how could I filter the custom taxonomy and display it. the JS is for firing the URL generated is working fine. the problem is the results page items are not showing. I have this code so far:

                  <?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>';                                                
                   }
      

//NEXT CODE IS GET THE CATEGORY ID AFTER CLICKED TO DISPLAY

                <?php
                  $terms = get_terms([
                    'taxonomy' => 'pdf_cat',
                    'hide_empty' => false,
                    ]);                                         // 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()
                ?>

and here is the js to fire the dropdown menu link when clicked:

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

//NEXT CODE IS TO THE DISPLAY

                     <div class="pdf-box">
                        <?php
                        $file = get_field('file');
                        if( $file ): ?>
                            <a href="<?php echo $file['url']; ?>" target="_blank"><?php echo $file['file']; ?>
                                <div class="service-list-col1">
                                <i class="fa-file-o"></i>
                                </div>
                                <div class="service-list-col2">
                                    <p><?php the_time('Y.m.d'); ?></p>
                                    <h3><?php the_title(); ?></h3>
                                </div>
                            </a>
                        <?php endif; ?>
                    </div>
maru
  • 35
  • 7
  • Is your question, “how can I get posts that have a specific taxonomy’s term assign to them”? If so, see this: https://wordpress.stackexchange.com/a/165617 – Chris Haas Dec 19 '21 at 13:16
  • I have two pages, 1st page is the newsletter.php where all the post are showed up. and once you filter the posts by its category, it supposed to proceed to the pdf_cat.php page where the filtered category will be showed up. – maru Dec 19 '21 at 13:43
  • I can't find the solution. hope someone can help me – maru Dec 19 '21 at 13:45
  • Hi @maru, unfortunately I’m on an iPad so I don’t have a developer console. It appears that you have an HTML `select`, and each `option` has a `value` that is a URL. You have some jQuery that is handling the form’s change event, and when that fires, you are setting the browser's location to the selected value. Does that summarize what you are doing? The drop down doesn’t work on my iPad for starters, not sure why, might be me. Is your problem that the JS isn’t firing, or that on the results page items aren’t showing? – Chris Haas Dec 19 '21 at 14:26
  • hi @ChrisHaas yes exactly. I have php code where all the categories will get and also its link id's through get_term_link. (Kindly see the updated post) and also I have JS which will firing the dropdown menu to its specific link. please let me know your thoughts – maru Dec 19 '21 at 14:40
  • JS is working fine. the problem is the results page items are not showing. – maru Dec 19 '21 at 14:47
  • 1
    This question needs more details in order to be solved. We need to see the `a` tag generated after `while ( have_posts() ) : the_post()`. We need to see the `href` attribute of the `a` tag. – Mokhless Dec 19 '21 at 18:10
  • hi @Mokhless please check my updated post. I added additional codes infos. hope you can help me – maru Dec 20 '21 at 00:20
  • @Mokhless I don't have a tag "href", since I am using the select option. here is the code I generated the URL Linkid's from my taxonomy foreach( $terms as $term ){ echo ''; } – maru Dec 20 '21 at 00:35
  • still trying to find the logic – maru Dec 20 '21 at 05:15
  • HI everyone I write a new post. I hope this time I explain it clearly https://stackoverflow.com/questions/70417765/page-for-my-custom-taxonomy-url-link-doesnt-show-up – maru Dec 20 '21 at 05:39

0 Answers0