You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为WordPress播客添加第二个分类筛选器的技术求助

WordPress播客添加第二个分类筛选器的技术求助

我现在需要给网站添加第二个播客分类筛选器,第一个已经可以正常使用,但不确定该怎么添加第二个。第一个筛选器是按播客类型筛选,第二个需要按名称筛选。我已经在functions.php里设置好了播客的自定义文章类型和分类法,那我还需要在这个文件里额外添加什么内容吗?毕竟第二个筛选器用的还是同一个分类法,只是筛选维度不同。

另外,我是不是需要把分类设置成父分类+子分类的结构?比如一个父分类组用来放播客类型,另一个用来放播客名称?

还有,怎么让两个下拉框分别只显示对应的选项——第一个下拉框只显示类型,第二个只显示名称?

<?php
$filter = get_query_var( 'podcast_category_filter' );

$args = array(
    'taxonomy'          => 'podcast_category',
    'selected'          => sanitize_text_field( $filter ),
    'name'              => 'podcast_category_filter',
    'hide_empty'        => false,  
    'orderby'           => 'name', 
    'value_field'       => 'slug',
    'echo'              => false,  
    'show_option_all'   => 'All podcasts',
    'option_none_value' => 0       
);
$select_category_html = wp_dropdown_categories( $args );
?>

<form method='GET'>
    <?php echo $select_category_html ?>
    <button type='submit'>Filter</button>
</form>

<div class="podcasts">

<ul>
    <?php $tax_query = array();

    
    if ( ( 0 != $filter ) && is_string( $filter ) && ( '' != $filter ) ) {
        $tax_query = array(
            array(
                'taxonomy' => 'podcast_category',
                'field'    => 'slug',
                'terms'    => sanitize_text_field( $filter ),
            )
        );
    }

    // Create a secondary query to avoid using the main query.
    $args = array_merge(
        array( 'post_type' => 'podcast' ),
        array( 'tax_query' => $tax_query )
    );
    $podcast_query = new WP_Query( $args );

    if ( $podcast_query->have_posts() ) :
        while ( $podcast_query->have_posts() ) : $podcast_query->the_post(); ?>

<li>
</li>
</ul>
</div>

备注:内容来源于stack exchange,提问作者Peggy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 11:09:39