Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按高级自定义字段(wordpress)中的值统计帖子_Php_Count_Wordpress_Posts - Fatal编程技术网

Php 按高级自定义字段(wordpress)中的值统计帖子

Php 按高级自定义字段(wordpress)中的值统计帖子,php,count,wordpress,posts,Php,Count,Wordpress,Posts,我试图统计那些在ACF模块的复选框中选中了相同值的帖子 我有一个用于单选按钮的代码,但它不适用于有多个选项的复选框: 到目前为止,我的代码是: function get_post_count_by_meta( $meta_key, $meta_value, $post_type) { $args = array( 'post_type' => $post_type, 'numberposts' => -1,

我试图统计那些在ACF模块的复选框中选中了相同值的帖子

我有一个用于单选按钮的代码,但它不适用于有多个选项的复选框:

到目前为止,我的代码是:

    function get_post_count_by_meta( $meta_key, $meta_value, $post_type) {


    $args = array(
            'post_type' => $post_type,
            'numberposts'   => -1,          
            'post_status'   => 'publish',
        );

        if ( $meta_key && $meta_value ) {
                if ( is_array($meta_value) ) {
            $args['meta_query'][] = array(
                'key' => $meta_key,
                'value' => $meta_value, 
                'compare' => 'LIKE');
        }

        else {
            $args['meta_query'][] = array('key' => $meta_key, 'value' => $meta_value);
        }   
    }

        $posts = get_posts($args);

        $count = count($posts);


    return $count; 

}
 $post_count = get_post_count_by_meta('test_field', 'Value 1', 'any');
echo $post_count;

当字段为复选框时,它始终响应0。$args查询一定有问题。有人能给我一个提示吗?谢谢,
numberposts
参数应该是
posts\u per\u page
()