$this->db->select("category.id, category.title, COUNT(`post.id`) as posts_count")
->from('category')
->join('post','category.id = post.category_id')
->where(array('post.category_id !=' => NULL, 'category.id !=' => NULL))
->group_by(array("category.id", "category.title"))
->get();