It’s been a rough few weeks for President Obama. Voters in so-called “Blue Wall” states seemingly rejected the vast majority of the president’s legacy.

Whether it was ObamaCare, lax immigration enforcement or the Trans Pacific Partnership, millions of voters (many of whom voted for him in 2008 and 2012) decided they didn’t want to hand the White House keys over to someone who campaigned almost entirely on the status quo.

Voters told Obama and the Democratic Party that they were out of touch with their concerns. So how did the president respond? Essentially: It’s all Fox News’ fault.

As he put it in a recent interview with Rolling Stone, the reason Democrats can’t attract voters beyond the East and West coasts isn’t their policies but the fact that “Fox News [is] in every bar and restaurant in big chunks of the country.”

Sure, Mr. President, millions of Americans across the country leave their jobs and homes at the end of the day, go to their neighborhood eatery or watering hole, watch “The O’Reilly Factor” and have their brains washed. Please.

The president is just making this up. Truth is, Obama — like other top Democrats — probably hasn’t been to many bars in the last eight years, even if he doesn’t mind declaring what’s on their televisions and how they’re being secretly turned against his party.

There is, of course, no conspiracy by the diner and bar owners of America to broadcast one single news channel, even if many do. But the president’s repeated singling out of a single network should concern all Americans, not just conservatives.

Fox News has been a consistent target for Obama’s frustrations, blaming the network, as he did in September, for creating a “very polarized society” and “churning out a lot of misinformation on a regular basis.”

The president’s recent hits on Fox just add to his long, pathological fixation on the cable news network. Even back in 2009, as e-mails obtained by Judicial Watch later showed, the Obama administration tried excluding Fox News from an interview with a Treasury Department official.

The behavior was so nakedly prejudicial toward the network that other members of the White House press pool refused to participate in the interview if Fox wasn’t allowed.

And conservatives are the ones responsible for a toxic media environment?

Oddly, Obama doesn’t think progressive media plays much of a role here — except that he thinks one way to help Democrats win elections is to make progressive causes “attract more eyeballs and make it more interesting and more entertaining and more persuasive.”

While the John Olivers and Samantha Bees of the world may not be among the more persuasive (or even entertaining) surrogates for the Democratic cause, it’s absurd to suggest the key to future political victories hinges on more talented entertainers lobbying for transgender bathroom access.

But the president goes further. The guy who ran one of the most tech-savvy campaigns in 2008 and 2012 doesn’t seem to like the Internet anymore — at least when it helps his political adversaries win. “The challenge,” according to Obama, “is people are getting a hundred different visions of the world from a hundred different outlets.” Sounds pretty good to me.

The president isn’t too comfortable with regular people having their own soapbox. No, the response to the democratizing of media, in Obama’s eyes, is “figuring out how [to] organize in a virtual world” and “better civics education for our kids.”

In other words, one bad election (for Democrats) means society, and the government, has to reevaluate its relationship with news outlets.

There’s no better way to put it: The president is stoking the flames of censorship. Instead of focusing on policy, helping the nation heal or just . . . going away, he’s pointing blame for his party’s failures at the press.

For all the talk about Donald Trump’s contentious relationship with the media, Obama’s language and actions toward Fox News and other conservative media outlets is just, if not more, toxic. If you don’t agree with Obama’s policy on health-care reform, you must be some ignorant yahoo.

Here’s some advice for the president: Instead of lambasting Fox News or something an aide saw once on social media, maybe take some time and think about why so many Americans are turning away from the mainstream media.

You might learn something, and your team might start winning again, too.