dongtiao2976 2018-01-29 05:56
浏览 22
已采纳

否则如果不工作,如果总是返回true,则选择其他选项

I make a function to return int based on COUNT, but else if not working. Could I miss something?

   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;
}
  • 写回答

1条回答 默认 最新

  • doucheng9634 2018-01-29 07:20
    关注

    QUESTION CLOSE !!

    I change my code to:

       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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?