duansha8764 2017-06-19 11:20
浏览 52

按复选框ACF字段的Wordpress过滤器不起作用

I'm trying to allow users to filter wordpress posts based on the values in an ACF checkbox field. So I have an options form:

<form name="SelectDigit" method="post">
        <select name="Digit">
            <option></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>                
        </select>
        <input type="submit"  value="Filter posts" />           
</form>     

Which passes through a value:

   <?php $SelectedDigit  = $_POST["Digit"]; ?>

To my WP Query:

        if (isset($_POST["Digit"]) && !empty($_POST["Digit"])){


            //args

            $args = array(
            'numberposts'   => -1,
            'post_type'     => 'post',
            'meta_key' => 'checkbox',
            'meta_value' => $SelectedDigit,
            'compare' => 'IN',
            );


        $wp_query = new WP_Query($args);


    if( $wp_query->have_posts() ): 

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

      the_field('title'); 

     endwhile;
    endif;
    }?>

It doesn't work. However, I also have a radio button ACF field. When I change my args to:

        $args = array(
        'numberposts'   => -1,
        'post_type'     => 'post',
        'meta_key' => 'radio',
        'meta_value' => $SelectedDigit,
        'compare' => '=',
        );

It works fine for radio fields. What's the difference? How can I get it work on checkboxes? I've asked ACF support, but they're not being very helpful... Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序