When Canadian filmmaker John Greyson was detained by police in Cairo on Aug. 16, his partner of 17 years went back in the closet.

Greyson had arrived in Cairo the day before along with an emergency room doctor named Tarek Loubani to work on a documentary about Loubani's work at the Al-Shifa Hospital in Gaza. This put them in the wrong place at the wrong time. The Egyptian military had just launched a bloody crackdown on supporters of ousted President Mohammed Morsi and thrown hundreds of people in jail.

Before his detention, the last time Greyson's partner Stephen Andrews, a Toronto artist, spoke to him was a confusing phone call during which Greyson and Loubani seemed to be getting kicked out of a cab. Then, for a terrifying 24 hours, Andrews didn't know where Greyson was. Finally, the Canadian foreign ministry informed him that the men had been thrown in jail in mass arrests that swept up 602 others.

In an account the men were later able to get to their friends, they said they had been arrested while asking for directions at a police checkpoint, then beaten while their captors "screamed 'Canadian.'" The men were never charged, though police eventually alleged they were involved in espionage and claimed they were carrying "spy drones." Probably most sensitive was footage Greyson shot of police attacking protestors in Ramses Square.

For 51 days they were held in cramped, roach-infested cells, "sleeping like sardines on concrete with the cockroaches." For more than two weeks, they went on a hunger strike to protest the conditions. They were denied phone calls and allowed only infrequent visits.

During this time, Andrews' only communication with Greyson was via notes — written in a "lover's code" — that his lawyers were allowed to read to him. "They were never signed 'Stephen.' They were signed 'S,'" Andrews told BuzzFeed after it was announced last weekend that Greyson had been released. On Friday morning, the Canadian finally left Egypt for home.

The duo's friends and family knew the reporting trip was risky. So they had come up with a strategy ahead of time for exactly this situation, taking into account Egypt's history of persecuting LGBT individuals. And that plan called for Andrews to become invisible.

He was still the next of kin communicating with the diplomats working on getting Greyson and Loubani released. But his name was absent from media coverage. Greyson's sister, Cecilia Greyson, was the spokesperson for the family. Activists and friends worked tirelessly to ensure that major news outlets would obscure the fact that Greyson was gay and omit that his queer-themed films were well known in arts and activist circles.

"I understand what the closet is and how difficult that is," said Andrews, who is in his fifties and came out in the 1970s. But, "I don't have to pick that battle [for recognition]…The battle isn't whether John's gay or not."

Concerns about how he would be treated if the knowledge spread came from all sides. Given that he was detained in a crowded Egyptian prison cell along with a good number of Islamist activists, getting Greyson out of jail alive was the bigger fight.

"The military is not always gay friendly," said Andrews wryly. "And with fundamentalism, it's a delicate issue."

They had a model for this approach: In 2005, Canadian peace activist James Loney was kidnapped in Baghdad along with three others by a little known group called the Swords of Righteousness Brigade, and was held hostage for more than four months. Loney's partner, Dan Hunt, hid their relationship on advice of the ministry of foreign affairs until Loney was released.

"On the day that James disappeared, I had to disappear too," Hunt told The Globe and Mail after Loney came home in March 2006. "That was a very painful thing in my life…because gay and lesbian people know that not being seen is so very hard, and because I wasn't seen, a big part of Jim's life also wasn't seen."

Andrews said they followed "the playbook for James Loney" because he understood how important it was to "control page one of Google Search." They couldn't erase word of Greyson's sexuality from the internet. But they could do everything in their power to push it into the background so that word wouldn't get inside the prison.

This meant they couldn't have any "gay coverage," said Sarah Schulman, co-founder of the MIX NY LGBT Experimental Film and Video Festival, who coordinated U.S. media outreach for the campaign to get Greyson and Loubani released. The friends and family wouldn't talk to any press that refused to agree to keep Greyson's sexuality out of the story.

Most major news outlets didn't touch the issue. The reporter who covered the story for The Guardian, Patrick Kingsley, said he simply felt "his sexuality just wasn't relevant to the story."

"It would be like saying, 'White filmmaker John Greyson,' or 'Arab doctor Tarek Loubani.' I briefly considered mentioning at one point that his films were concerned with gender — but on reflection, it didn't seem relevant," Kingsley said. "When I spoke to [the friends and family] on the phone, they never mentioned" a request to omit mention of his sexuality.

The New York Times put their story about Greyson on the front page, and clearly thought his sexuality was relevant. But the tortured language of reporter David Kirkpatrick's story shows they were willing to go to some lengths to honor the request. He described Greyson as "a liberal Toronto filmmaker whose work often focuses on cosmopolitan sexual themes" and makes "highly un-Islamic movies about sexual politics."

Michael Slackman, the New York Times's deputy foreign editor, explained in an email that the paper was asked not to mention Greyson's sexuality by his lawyer because, "Homosexuality is treated as a crime in Egypt and gays are subject to discrimination and violence."

"David discussed this with his editor who agreed that Mr. Greyson's sexuality was not central to the article. He did not, for example, note that Tarek Loubani was heterosexual," Slackman said. "However, since the two men were being accused of belonging to the Muslim Brotherhood, it was relevant to note that both were liberals, not Islamists, and that Mr. Greyson, in particular, made films very inconsistent with the Brotherhood's ideas about Islamic values."

This also led to some ironic situations beyond the media realm, Schulman said. When she led a delegation of Americans to the Egyptian consulate in New York in late September to express their concern for Greyson, all were gay. But they passed. "My delegation was entirely queer… So what? We're all middle-aged college professors. It's not so obvious."

But they didn't manage to keep Greyson's sexuality entirely hidden — or even off of page one of Google search. In fact, the first thing that comes up is Greyson's Wikipedia entry, which says Greyson is "a Canadian filmmaker, whose work frequently deals with gay themes."

The gay press was particularly oblivious to the issue. "Prominent gay filmmaker John Greyson Arrested in Egypt," wrote the blog Towleroad on Aug. 19. The Advocate ran the headline "Gay Filmmaker Detained in Egypt, Launches Hunger Strike" on Sept. 21. Out Magazine published "Will Egypt Release Openly Gay Filmmaker?" on Sept. 27.

"No one [of Greyson's friends and family] has contacted any of the editors here as far as I'm aware, and this is the first time I heard that it was a topic that the family was trying to keep 'quiet,'" said Out Executive Editor Jerry Portwood when asked about their coverage. Andy Towle of Towleroad said he was similarly unaware the issue was sensitive. "I had no idea that keeping his sexuality out of the news was a concern, nor did we receive any communication that I am aware of from friends and family."

The major outlets' silence on the issue didn't escape the notice of some of Greyson's critics. On Oct. 8, when Greyson and Loubani had been freed from prison but refused permission to leave the country, Globe and Mail columnist Margaret Wente blasted Greyson for his work in support of Palestinians, including his involvement in the organization Queers Against Israeli Apartheid.

"Many of the media haven't mentioned that Mr. Greyson is gay for fear that it would go worse for him in homophobic Egypt," she wrote. "But it's no secret; his sexual orientation is very public. The real mystery is how anyone concerned with gay rights could support a viciously homophobic movement like Hamas."

But the case got little attention inside Egypt; what little coverage there was only mentioned that they were foreigners, not that one was gay. And it turned out that this kind coverage from gay media "didn't make a difference," said Schulman.

The prestigious "global press" is what really mattered, Schulman said, because it was what got noticed by the Egyptian elite and shared in social networks. The activists noticed that the British press was especially important — The Guardian's story got particular traction on Facebook.

It still isn't clear what finally persuaded the Egyptian authorities to let the men go. But last weekend, Andrews got to speak to his partner for the first time in more than two months.

Andrews says that his experience living through the AIDS crisis has helped him figure out ways to continue functioning during the ordeal, especially his sense of humor. When asked whether he planned a special meal to celebrate Greyson's return, he replied, "Yes. I'm planning on having him for dinner."