微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何查询以获取正确的计数编号acf 字段/wordpress?

如何解决如何查询以获取正确的计数编号acf 字段/wordpress?

当前帖子的firstsubmission字段(acf字段)为空。
所以,查询应该显示 0,但它显示 1。
我尝试了以下代码,它们都显示 1.
请告诉我如何获得正确的计数 0?

    $posts = array(
    'author'            => get_current_user_id(),'posts_per_page'    => -1,'post_title'        => get_the_title(),'post_type'         => 'infosubmission','Meta_query'        => array(
            array(
            'key'       => 'firstsubmission','value'     => 'done'
        )
     )
  );

$post_b = new WP_Query( $posts );
$the_count = count($post_b); 
echo 'COUNT:' .$the_count;

$posts = get_posts(array(
    'author'            => get_current_user_id(),'Meta_key'          => 'firstsubmission','Meta_value'        => 'done'
));

$the_query = new WP_Query( $posts );
$the_count = count($the_query); 
echo 'COUNT:' .$the_count;

$infopost = [
    'author'         => get_current_user_id(),'post_type'      => 'infosubmission','posts_per_page' => -1,'post_title'     => get_the_title(),'firstsubmission' => 'done'
];

$info_posts = new WP_Query($infopost);
$info_count = count($info_posts);   
echo 'COUNT:' .$info_count;

enter image description here


谢谢。

解决方法

/* please replace below snippet in your code */

$posts = get_posts(array(
    'author'            => get_current_user_id(),'posts_per_page'    => -1,'post_title'        => get_the_title(),'post_type'         => 'infosubmission','meta_key'          => 'firstsubmission','meta_value'        => 'done','meta_compare'   => '=' 

));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。