我根据COUNT创建一个返回int的函数,否则如果不起作用。我可以错过什么吗?
function kv_get_task_count() {
global $wpdb;
if (filter_status('new')):
$count_post = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
WHERE post_type ="screening"
AND post_status ="new"
' );
elseif (filter_status('pending_review')):
$count_post = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
WHERE post_type ="screening"
AND post_status ="pending_review"
' );
else:
$count_post = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
WHERE post_type ="screening"
AND post_status ="new"
OR post_status ="pending_review"
' );
endif;
return $count_post;
}
答案 0 :(得分:0)
问题关闭!!
我将代码更改为:
function kv_get_task_count() {
global $wpdb;
if ($_REQUEST['post_status'] == 'new'):
$count_post = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
WHERE post_type ="screening"
AND post_status ="new"
' );
elseif ($_REQUEST['post_status'] == 'pending_review'):
$count_post = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
WHERE post_type ="screening"
AND post_status ="pending_review"
' );
else:
$count_post = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
WHERE post_type ="screening"
AND post_status ="new"
OR post_status ="pending_review"
' );
endif;
return $count_post;
}