As a presidential candidate, Donald Trump presented himself as a social liberal seeking to move Republicans left on LGBT rights. (Chip Somodevilla/Getty Images)

For decades leading up to President Trump’s Wednesday tweets announcing a ban on transgender people in the military, the businessman-turned-politician has approached the LGBT community on nonideological terms.

Trump’s relationships with LGBT people, and his evolving positions on issues, have been transactional, according to people who have interacted with him, focused largely on how the community might affect his interests in the moment.

Only a year ago, candidate Trump presented himself as a social liberal seeking to move the Republican Party left on gay, lesbian, bisexual and transgender rights.

He vowed that he would do more than Democrat Hillary Clinton to protect LGBT people. He defended the rights of Caitlyn Jenner, the country’s most well-known transgender advocate, to use whichever bathroom she wanted in Trump Tower. And he added “Q” to his discussion of the “LGBTQ community” in his Republican National Convention speech to show he was in the know.

“People are people to me, and everyone should be protected,” he told The Washington Post in a May 2016 interview.

President Trump speaks to the American Legion Boys Nation and the American Legion Auxiliary Girls Nation at the White House on Wednesday, the same day he announced a ban on transgender people in the military. (Jonathan Ernst/Reuters)

But circumstances have been changing since Trump entered the White House.

While his staff has met with LGBT advocates and he has hired several New Yorkers who have supported LGBT rights in the past, Trump’s administration has taken positions more in tune with the president’s social conservative base. It has quietly rolled back protections for transgender schoolchildren, removed information about LGBT rights from the White House website and declined to recognize LGBT Pride Month in June.

Trump’s tweets on Wednesday delivered yet another a victory to the political right — including many House Republicans whose support he needs for his policy agenda — while surprising many Republican LGBT activists who had hoped he would end the culture war within the party.

Those familiar with Trump say his stances aren’t contradictory, but rather illustrate the consistency of his instincts to shape his views depending on the moment.

“I don’t believe Donald Trump has an personal animus toward LGBT individuals,” said Gregory T. Angelo, president of the Log Cabin Republicans, which represents gay conservatives and allies. “This smacks of politics, pure and simple.”

Angelo, who once labeled Trump the “most pro-LGBT Republican nominee in history,” said there seems to be a political calculation that reigniting the transgender rights debate will help galvanize conservative voters in the 2018 elections and expand GOP majorities in Congress. A more conservative Congress would allow Trump to achieve more legislative victories, such as his coveted border wall with Mexico or erasing President Barack Obama’s health-care overhaul.

“If you think you’re going to repeal and replace Obamacare by using LGBT soldiers as a political football, you’ve got another thing coming,” Angelo said.

The White House on Wednesday sought to portray Trump’s announcement as a narrow policy matter and not a reflection of the president’s personal views toward the transgender community.

When asked if this means the president will also reconsider allowing transgender individuals to serve in his administration, Trump spokeswoman Sarah Huckabee Sanders said no, adding that the ban was a “decision based on what was best for the military and military cohesion.” She denied that decision was politically motivated.

Trump has long demonstrated a laissez-faire attitude toward sexual orientation.

In the 1980s, when the major players in the Manhattan real estate world were scoffing at the talkative newbie from Queens, Trump found a mentor in attorney Roy Cohn, who helped Trump perfect the art of the counterattack. It was well known among the New York elite, but not discussed, that Cohn was a closeted gay man — which never seemed to bother Trump.

Trump provided early donations for AIDS research, giving profits from Wollman Rink, the Manhattan ice rink he renovated, to the Gay Men’s Health Crisis organization. In 1992, Trump Taj Mahal also hosted a “Clash of the Legends” event featuring basketball players Kareem Abdul-Jabbar and Julius Erving in which a portion of the proceeds went to AIDS research, according to Newsday reports at the time.

At the Trump Organization, he hired and promoted Abraham Wallach, who recalled Trump shrugging off the news that he was gay.

Trump invited Wallach and his partner, David, to fly down with him to spend weekends at Mar-a-Lago, his private club in Palm Beach, Fla., which is believed to be the first club on the island to accept gay couples.

“He’ll do a deal irrespective of their sexual preference or a political issue,” said Wallach, who was executive vice president for acquisitions at Trump’s company. “It mattered if he could benefit from your talent. That was true with me, and that was true with Roy Cohn.”

The first time Trump explored a bid for the presidency, in 1999, he presented one of the most liberal policy platforms regarding the LGBT community at the time.

Trump proposed not only repealing the ban on gays and lesbians serving openly in the military, he also said that gays and lesbians should be a protected class under the Civil Rights Act. Trump recommended that same-sex civil unions receive the same benefits and protections as those in traditional marriages.

“It’s very simple,” Trump told the Advocate magazine about his gay rights proposals.

His positions at the time also made political sense.

He was preparing to do battle with conservative firebrand Pat Buchanan for the Reform Party nomination, and Trump was angling to distinguish himself as an inclusive person who didn’t speak ill of minorities and gay people.

As a businessman operating in areas dominated by liberal politics — New York real estate and, as the star of “The Apprentice,” the entertainment industry — Trump demonstrated a live-and-let-live attitude in his personal interactions with LGBT people.

After completing a 2005 boardroom scene for “The Apprentice,” Trump told the show’s first openly gay competitor that he saw advantages in hiring gays in his business.

“I love having gay people work for me; they are the most trustworthy people, especially around women,” Clay Lee recalled Trump saying to him. Trump’s logic, according to Lee: With so many women around his modeling agency, the businessman worried about straight employees harassing them. “I can’t afford to have that liability,” Trump added, according to Lee.

Lee said he came out to Trump during filming after his team produced a poorly received workplace video about sexual harassment.

“Are you a homosexual, Clay?” Trump asked in an exchange that was caught on camera.

When Lee said yes, Trump seemed welcoming. “I like steak. Someone else likes spaghetti,” Trump remarked, according to Lee. “That’s why we have menus in restaurants.”

But Trump’s approach changed as he cultivated his conservative credentials, fueled in part by the popularity he gained aligning with conservatives by promoting the conspiracy that Obama was not born in the United States.

In 2011, Trump told the Des Moines Register that “as of this moment,” he did not believe same-sex couples in civil unions should receive benefits equal to those of heterosexual marriages. Trump added that his “attitude was not fully formed” on the issue, even though it once was, an equivocation that echoed similarly hedged statements from politicians in both parties at the time.

Those who knew Trump challenged him about this waffling.

On a radio segment with Howard Stern in 2013, before Stern got Trump to criticize Kim Kardashian’s appearance, the shock jock confronted Trump on whether his positions on gay rights were for political gain.

“If I was alone with you, and you and I were just having a drink, I don’t think you care about same-sex marriage,” Stern said. “I think you’re all for it. I know you.”

“It’s never been an argument discussed with me very much,” Trump said. “People know it’s not my thing, one way or the other.”

As LGBT rights organizations concentrated during that time on promoting the legalization of same-sex marriage, and many politicians began to embrace the idea, Trump was moving in the other direction.

George Takei, a gay rights advocate best known for originating the character “Sulu” on the first “Star Trek” series and as a former “Apprentice” contestant, said he tried over lunch one day in 2012 to quiz Trump about his position against same-sex marriage. Takei got nowhere. But Trump mentioned how he attended the wedding of a Broadway producer and told his host, “You gays do everything beautifully.”

“He just kept saying, ‘I just believe in traditional marriage,’ ’’ Takei recalled. “I don’t think he had much depth on the issue.”

Meanwhile, gay conservatives were increasingly looking to Trump as an ally as he became more interested in politics.

As a leader in the party, Trump has sent mixed signals. While the nation debated last spring which bathrooms transgender individuals should use, Trump said that visitors to Trump Tower could pick for themselves — and then, hours later, he said that as a policy matter it is best left to states to decide.

Trump also said that he opposed same-sex marriage — only to say after the election that he’s “fine” with it and considers it an issue that has been “settled in the Supreme Court.”

After a mass shooting at a gay nightclub in Orlando in June 2016, Trump strongly denounced violence against LGBT individuals and promised to protect them from terrorists more than Clinton would.

He presented his advocacy for the community as a defense against radical Islam, an unusual position that managed to mix rhetoric embraced by conservatives and liberals.

“As your president, I will do everything in my power to protect our LGBTQ citizens from the violence and oppression of a hateful foreign ideology,” he said during his GOP convention speech.

A person familiar with Trump’s preparations, speaking on the condition of anonymity, said he ad-libbed the addition of the “Q,” which has become popular parlance referring to those who question their gender identity or sexual orientation.

But Trump’s selection of Mike Pence as his running mate showed that Trump was not neglecting his conservative base. As Indiana governor, Pence had advocated that families use conversion therapy to turn their gay children straight.

Since his inauguration, several LGBT advocates have given Trump plaudits for some of his work — including extending the ban on discriminating on the basis of sexual orientation in the federal government and asserting violence against gays as a reason to ban travelers from six majority-Muslim countries.

Joseph Murray, a Mississippi lawyer and owner of the Facebook page LGBTrump, supported the president’s stance on the military.

“While I have great respect for trans people, the military is not a place for social engineering,” Murray said. “A trans person struggle, while very real, should not turn it into an experiment in which the military serves as a petri dish.”

Others saw Trump’s announcement as a sign that his past assurances were not worth counting on.

Jenner, who visited the White House only a few months ago to talk about transgender rights with Trump aides, made her feelings clear in a tweet shortly after the president’s announcement.

“There are 15,000 patriotic transgender Americans in the US military fighting for all of us. What happened to your promise to fight for them?”

Kayla Epstein and Sandhya Somashekhar contributed to this report.