最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dropdown - Trying to get categories and sub-category listing

programmeradmin1浏览0评论

I am trying to implement this: The problem is I am not getting the expected output after selecting categories/sub-categories from the dropdown list. I know I have messed up and I don't know what I should do now.

Code to get the dropdown menu having category and subcategory:

<form action="<?php bloginfo('url'); ?>" method="get">
     <div>
     <?php
          $taxonomies = array('categories'); 
             $args = array('orderby'=>'name','hide_empty'=>false);
             $select = get_terms_dropdown_grade_level($taxonomies, $args);
             $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
             echo $select;
        ?>
        <input type="submit" name="submit" value="Select" /> 
     /div>
</form>

`
To get listing after selecting category/sub-category from the drop-down menu

$terms = get_the_terms( $post_id, 'categories' );
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
 
    foreach ( $terms as $term ) {
    
        //View member by group/category
        $listing_members = get_posts(array( 
                'post_type' => 'resources', 
                'posts_per_page' => 20,
                'tax_query' => array(
                array(
                    'taxonomy'         => 'categories',
                    'field'            => 'slug',
                    'include_children' => false,
                    'terms'            => $term->slug,
                

                )
            )
        ));
      
        foreach ( $listing_members as $post ) {
           ?>
            <tr>
             <td><span class="tablesaw-cell-content"><a><?php the_field('name'); ?></a></span></td>
             <td><span class="tablesaw-cell-content"><?php the_field('organization'); ?></span></td>
             <td><span class="tablesaw-cell-content"><a><?php the_field('profile_link'); ?></a></span></td>
             <td><span class="tablesaw-cell-content"><?php the_field('organization_link'); ?></span></td>
             <td><span class="tablesaw-cell-content"><a><?php the_field('contact'); ?></a></span></td>
             <td><span class="tablesaw-cell-content"><?php the_field('notes'); ?></span></td>
            </tr>
        <?php }
    }
} 

  
发布评论

评论列表(0)

  1. 暂无评论