President Donald Trump ripped a South Carolina Republican congressman who has opposed the president in the past -- and made light of his 2009 extramarital affair that occurred while he was governor of the state.

In a tweet, Trump criticized Rep. Mark Sanford (R-Beaufort) as "unhelpful to me in my campaign to MAGA" and endorsed his primary opponent, business executive Katie Arrington.

In June 2009, Sanford went unseen for several days from his post in the Capitol in Columbia.

Aides famously told the press that he was hiking part of the 2,200-mile Appalachian Trail, which traverses mountains just west of the Palmetto State on its path from Springer Mountain, Ga. to Mount Katahdin, Maine.

Sanford was later spotted returning to the state from Buenos Aires -- thousands of miles away -- where he said he spent time with a woman who was not his then-wife.

After the affair, Sanford resigned his post at the Republican Governors Association and former First Lady Jenny Sanford filed for divorce.

"Mark Sanford has been very unhelpful to me in my campaign to MAGA. He is MIA and nothing but trouble. He is better off in Argentina," Trump wrote on Twitter, going on to endorse his opponent in the Low Country district.

Gutfeld: WH Video for Kim Jong Un 'A Sales Presentation on Freedom'

Former CIA Korea Analyst: 'Vague Statement' After Singapore Summit Does Not Mean Kim Will De-Nuclearize

"I fully endorse Katie Arrington for Congress in SC, a state I love. She is tough on crime and will continue our fight to lower taxes," Trump said.

Politico reported this week that Sanford that Sanford has spent years "torching Trump," despite being a member of the ultra-conservative House Freedom Caucus.

"I think it’s entirely appropriate to say 'I agree' when I agree and 'I disagree' when I disagree. That’s the American way," Sanford, 58, said in expressing his occasional differences with Trump.

Trump made the endorsement of Arrington only hours before the primary election polls closed Tuesday in the Palmetto State.

Tarlov: People on Both Sides Believe Nikki Haley Could Be First Female President

'Will You Give Up Your Nuclear Weapons?': CNN's Acosta Shouts Questions at Kim, Trump