If the church is the magisterium, how come it gets so much so wrong?
The assumption behind this question is that if there is a magisterium, it must be infallible in everything it does. I'm not sure where you are getting the basis for that assumption. But the Church is protected from the possibility of error only when promulgating doctrine to be believed by all believers everywhere (i.e. from Ecumenical Councils and/or ex cathedra teachings by the successor of Peter). Peter was a sinner. Jesus rebuked him. Paul rebuked him. But, he nevertheless held the apostolic office that Jesus gave him. (You can see that it is an office, in Acts 1, when Judas's office had to be filled.) Our leaders are fallible sinners. But they are nevertheless the vessels God has chosen by which to lead His Church. The Montanists, Novatians and Donatists erred by using what they viewed as laxity/error in the Church as grounds for schism.
-A8