President Donald Trump’s announcement last Friday that he would end the longest partial government shutdown in U.S. history without securing funding from congressional Democrats for his long-promised border wall came after weeks of brutal headlines and sagging poll numbers.

But when Trump arose the following morning, he did not devote his time to convening his White House advisers to figure out what went wrong or reaching out to Republican congressional leaders to plot their next move.

Instead, he did the same thing he’s done on countless days of his administration: He turned on his television, tuned in to his favorite program, Fox & Friends, and started tweeting about what he saw.

For more than a year, I’ve studied this Trump-Fox feedback loop, the president’s habit of live-tweeting his favorite shows on the right-wing cable news network. I’ve tracked several hundred of the president’s often-hyperaggressive tweets back to particular segments on Fox News and its sister network, Fox Business, that caught the president’s eye.

Fox helped build Trump’s political brand and fuel his electoral rise, and in recent years has remade itself as a propaganda outlet in support of his presidency. Trump, in turn, has long been obsessed with the network. His worldview and decision making are shaped by the former network personalities with whom he has stocked his administration, the “Fox cabinet” of current stars he reaches out to for advice, and the hours of Fox programming he reportedly watches each day.

Having a superfan in the White House has given Fox outsized influence over both the news cycle and federal policy. The network’s efforts to infuriate its audience—over everything from NFL players kneeling in protest during the national anthem to a caravan of migrants slowly approaching the U.S. southern border—can trigger outraged presidential tweets, instantly turning the network’s particular fixations into national news.

And because Fox’s staff and guests are aware that Trump could be watching at any time, they often use the network’s platform to try to reach him directly, seeking to shape his decisions on political strategy, legal tactics, pardons, personnel, and more.

No story has demonstrated the power of this Trump-Fox feedback loop like the partial government shutdown.

Trump’s incessant craving for validation from the network’s conservative commentators triggered his initial refusal to sign any legislation funding the government that did not include money for a border wall, and then that need sustained his intransigence over the following weeks. His eventual cave shows the limitations of prioritizing the whims of right-wing infotainers during congressional negotiations. But there is no evidence Trump has learned anything from the crushing defeat, suggesting that he will continue trying to make policy with respect to the wall and other issues, on the basis of whether it pleases Fox hosts.

In September, I argued that Trump’s Fox affinity made a government shutdown inevitable. The same pattern kept playing out: House and Senate leaders would agree to a spending bill, Fox commentators would claim the bill betrayed the president’s base because it didn’t include wall funding, Trump would angrily tweet about the Fox segments and send Washington into chaos, and Mitch McConnell and Paul Ryan would have to talk him into supporting the legislation. With Trump publicly declaring that a shutdown was a “great political issue” and explicitly citing Fox hosts as his inspiration for the tactic, the situation seemed untenable.

Three months later, it finally came to a head. As the December deadline to renew government spending loomed, Fox personalities again began urging Trump to shut down the government rather than sign a spending bill that didn’t include money for the wall. Once again, Fox’s influence was matched against that of Republican congressional leaders, who warned the president that a shutdown would be a grave tactical mistake.

But this time, Fox News won.

When the White House signaled that it was backing away from its wall-funding demand, furious network commentators insisted that Trump reconsider and instead shut down the government. The calls were loudest on Fox & Friends, the president’s favorite morning cable show. “If there's not a shutdown,” declared co-host Steve Doocy, “he’s going to look like a loser.”

Goaded by those he typically counts on for support, Trump reportedly “seethed and panicked” about the criticism, and then took their advice.

The president’s propagandists were jubilant. As portions of the government shuttered and hundreds of thousands of federal employees worked without pay for weeks, Fox’s airwaves were filled with cheers for the president and exhortations for him to remain firm. The hosts gave little indication of Trump’s grave political peril—to the contrary, they urged the rest of his party to stick with him regardless of the consequences. “If this takes 150 days, I think the Republican Party needs to stand united with the president,” argued Sean Hannity.

Trump made clear throughout the shutdown that he was prioritizing the support of Fox’s hosts over all other considerations. He consulted with Hannity and Dobbs for strategic advice about how to handle the shutdown, gave a national address in which he ripped language from their shows, and showed up on Fox programs to make his pitch directly to their audiences.

And as federal workers missed paychecks and his poll numbers plummeted, the president kept his television turned to the fawning reports of his favorite network and his iPhone open to Twitter. Trump sent at least 60 tweets parroting the network’s programming over the course of the shutdown.

The president trumpeted the polls Fox cherry-picked to suggest he was winning the shutdown:

He cribbed statistics the network aired about “Walls Around The World”:

He claimed that “Only a Wall” could protect Americans from a caravan of migrants the network repeatedly reported on:

He pushed Fox’s attacks on congressional Democrats who refused to support wall funding:

And he promised Doocy that he wouldn’t “cave”:

Cozying up to Fox News may have made Trump president. But as a legislative strategy, it was a total failure. It proved impossible for Trump to simultaneously ensure the support of far-right media figures accountable only to their audience and make a deal that attracted Democratic votes.

Fox’s own personalities understood the dynamic at play: During one heated debate, political analyst Juan Williams declared that Hannity was one of the right-wing commentators “running the government.” And Republican senators knew it too: One told Axios that Trump son-in-law Jared Kushner’s reported effort to try to end the stalemate with a major deal was impossible, saying, “Trump can withstand Ann Coulter. He can't lose Hannity and the rest.”

Hampered by these tensions, the president’s strategy eventually collapsed. With Democrats refusing to negotiate until he agreed to reopen the government, some federal workers beginning to revolt, and Republican senators on the verge of abandoning him, Trump finally gave in after 35 days, agreeing to reopen the government for three weeks while Congress attempts to negotiate an immigration package.

Trump’s decision to fold divided his Fox allies—even the hosts who had counseled the president on his shutdown strategy. Hannity offered a vigorous defense of his decision, arguing that “anyone out there” who is “thinking President Trump caved today, you don't really know the Donald Trump I know.” For Dobbs, however, the news was “a victory for Nancy Pelosi... and to deny it is to try to escape from reality.”

But neither Dobbs nor the president appeared to hold a grudge—by Thursday morning, Trump was tweeting about the previous night’s episode of Dobbs’ show, using the Fox host’s talking points as evidence that a border wall is necessary. Based on that program, Trump argued that Republicans negotiating an immigration deal “are wasting their time” because Democrats will not provide money for the “DESPERATELY needed WALL.” “I’ve got you covered,” he ominously added.

That seemed to be a reference to Trump’s likely endgame: declaring a national emergency in order to divert previously appropriated federal funds to wall construction. Ever since Trump first suggested that he might take that step in early January, Fox hosts have been urging him to do it, claiming that, in Dobbs’ words, the “only way forward” is for Trump to “simply sweep aside the recalcitrant left in this country” and do so.

Republican congressional leaders keep warning Trump that declaring a national emergency is a terrible idea that won’t serve his ends, and up until now, he’s listened to him. But we’ve seen how this played out before. The president will continue to wallow in Fox’s programming, as night after night its hosts tell him that the declaration is his only way to win. And eventually, he will listen.