Php 按自定义分类筛选WP_查询

Php 按自定义分类筛选WP_查询,php,wordpress,custom-taxonomy,Php,Wordpress,Custom Taxonomy,我试图用我最近创建的一个函数来解决一个问题。下面是一段代码,它创建了一个下拉字段,每个字段代表特定的“合作伙伴公司”。代码工作得很好 function fnc_select_1() { $args = array( 'post_type' => 'freecourses', 'orderby' => 'meta_value', 'status' => 'publish', 'order' => 'D

我试图用我最近创建的一个函数来解决一个问题。下面是一段代码,它创建了一个下拉字段,每个字段代表特定的“合作伙伴公司”。代码工作得很好

function fnc_select_1() {

    $args = array(
        'post_type' => 'freecourses',
        'orderby' => 'meta_value',
        'status' => 'publish',
        'order' => 'DESC',
        'meta_key' => 'validation_date',
    );

    $the_query = new WP_Query($args);

    if ($the_query->have_posts()):

        while ($the_query->have_posts()) : $the_query->the_post();

                if(have_rows('validation_date')): 
                    while (have_rows('validation_date')) : the_row();  

                    if( get_sub_field('company')) {
                        $firm_array[] = get_sub_field('company');
                    }                                                                                                               

                    endwhile; 

                    wp_reset_query();

                else :
                    // no rows found
                endif;

        endwhile;

        $firms = array_unique($firm_array);
        natsort($firms);

        echo '<select type="text" class="form-control" name="company" id="company">';
          echo '<option value="">company</option>';
        foreach ($firms as $firm) {
            echo '<option value="'. $firm .'">'; 
            echo $firm;                                 
            echo '</option>';                                                   
        }
        echo '</select>';

    endif;  
}
add_shortcode( 'select_1', 'fnc_select_1' );
对于我的wp_查询参数,我想我可以添加:

'tax_query' => array(     
    'relation' => 'AND',                 
      array(
        'taxonomy' => 'type',  
        'child_of' => $childno
      ),
),
但它不起作用。它根本不显示下拉列表


那么问题出在哪里呢?

你从哪里得到的
child\u?没有提到任何这样的参数。@04FS-你是对的。。我的问题。我从get_terms那里拿到的。。那么你知道如何实现我想要的吗?要通过术语id进行过滤,请使用
terms
参数。如果文章中的术语是您要查找的术语的子项,则会自动将其包括在内。如果您不想这样做,可以将
include\u children
设置为false。
'tax_query' => array(     
    'relation' => 'AND',                 
      array(
        'taxonomy' => 'type',  
        'child_of' => $childno
      ),
),