PITTSBURGH — Adam Wainwright is still in search of his best stuff. His bat made sure his best wasn’t necessary.

The St. Louis ace drove in three runs and survived five occasionally bumpy innings to pick up his first victory since mid-July as the Cardinals drummed the staggering Pittsburgh Pirates 12-6 on Monday.

Wainwright hit an RBI-double off Chad Kuhl (3-3) in the second and added a two-run single in the fourth as the Cardinals held on to the second wild card spot in the National League by sending the Pirates to their seventh straight loss.

“We needed that win,” Wainwright said. “We need every win that we can get coming down the stretch. Any part that I can play in that is a treat for me, a privilege.”

Wainwright (10-8) allowed four runs and struck out five as his ERA rose to 4.61 while picking up his first victory since July 16. He hardly needed to be sharp as the Cardinals battered Pittsburgh’s beleaguered pitching staff. Jedd Gyorko and Matt Adams homered for St. Louis to extend the team’s streak of games with at least one home run to a club-record 24.

Andrew McCutchen and Adam Frazier hit home runs for the Pirates, who have been outscored 47-22 during their current slide. A week ago Pittsburgh was well within striking distance of the Cardinals for a playoff spot but have fallen 4 1/2 games behind St. Louis and dropped below .500 (67-68) for the first time since July 2.

“We’re trying to figure ourselves out and get out of this and get back to playing baseball the way we want to play,” shortstop Jordy Mercer said. “We just have to keep going.”

St. Louis pounded out 14 hits — eight for extra bases — against five pitchers and wasted little time getting to Kuhl, who has been steady if not spectacular since joining the rotation full-time a month ago.

Wainwright’s double to the wall in center field put the Cardinals in front and Stephen Piscotty’s two-run double later in the inning gave Wainwright an early cushion, one he flirted with giving away. Pittsburgh touched him for two runs in the bottom of the inning but Wainwright avoided major damage.

“I hate giving up runs after we score,” Wainwright said. “That’s driving me crazy. But what we did do well there is we held them to two. We could have let that inning get away from us, and we didn’t.”

Jeff Locke came on relief of Kuhl in the third and the Cardinals quickly went to work. Kolten Wong’s RBI single against him made it 4-2 and Gyorko opened the fourth with a long home run down the left-field line for his 26th of the year.

Wainwright’s bloop to left later in the inning pushed St. Louis’ lead to six runs and allowed Wainwright to leave after five innings in which he needed 93 pitches to get 15 outs.

“He was at 93 pitches, and we’re in September,” Cardinals manager Mike Matheny said. “The first two (innings) were stressful. To me, we’ve got a lead that we think our bullpen can hold. I guess your greatest argument (for leaving him in) is you want to see him hit again.”

TRAINER’S ROOM

Cardinals: Piscotty left in the fifth inning after being hit in the wrist with a pitch though Matheny said X-rays were negative. … RHP Mike Leake will return after a bout with the shingles when he starts on Wednesday. … C Brayan Pena is finally healthy after battling injuries much of the season but the team will not use him to catch a full game.

Pirates: C Francisco Cervelli was taken out of the game after the fourth inning with discomfort in his left thumb. … C Elias Diaz is being evaluated for cellulitis in his left leg and will be re-evaluated on Thursday.

UP NEXT

Cardinals: Rookie Luke Weaver makes his fourth major league start on Tuesday. Weaver is 1-2 with a 3.86 ERA and gave up three runs over six innings in his last start against Milwaukee.

Pirates: Veteran Ryan Vogelsong (3-4, 3.56 ERA) will make his ninth start of the season and seventh since returning from the DL on Aug. 4 after missing more than two months while recovering from facial fractures sustained when he was hit by a pitch on May 23. Vogelsong is 3-7 with a 5.75 ERA in 22 appearances against the Cardinals.