[英]How to query to get the correct count number (acf field / 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(),
'posts_per_page' => -1,
'post_title' => get_the_title(),
'post_type' => 'infosubmission',
'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;
/* 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' => '='
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.