President Trump addresses the National Farm Bureau Federation's 100th convention in New Orleans on Jan. 14. (Carlos Barria/Reuters)

President Trump sought to rally thousands of farmers here behind his push for a border wall, but he offered one exception to his hard-line immigration stance, promising to allow seasonal farmworkers to more easily enter the country.

Trump spent most of his hour-long address to the American Farm Bureau Federation’s annual convention defending his decision to shut down the government over the fight for funding for a border wall and railing against the dangers of drugs and undocumented immigrants.

But speaking to farmers, who have faced a shortage of temporary workers as the economy has strengthened, Trump pledged to pursue changes to immigration laws that would “actually make it easier for them to help the farmers because you need these people.”

“A lot of people don’t understand this. You need people to help you with the farms. I’m not going to rule that out,” Trump said, drawing cheers from the crowd.

The president’s remarks, coming on the 24th day of the longest partial government shutdown in the country’s history, aimed to solidify support among a key constituency at a time when the Trump administration remains locked in a trade war with China that has negatively affected some agricultural sectors.

Chinese purchases of U.S. soybeans plummeted after the trade war began this summer, according to the Department of Agriculture, although Beijing did buy a small quantity of U.S. soybeans in December.

The farming federation has stood by Trump, even as its delegate body was set to debate Tuesday whether to toughen its policy stance on tariffs as a result of Trump’s trade war.

Trump spoke only briefly about his trade dispute with China and said talks with Beijing were “going very well.” He touted a revised trade accord between the United States, Mexico and Canada and urged Congress to ratify that deal.

And he said the Agriculture Department is “doing everything within its power to help farmers deal with the ongoing shutdown.”

Of the standoff with Democrats over Trump’s refusal to sign a spending bill without at least $5.7 billion in border wall funding, the president said: “We’re fighting very hard to defend our nation.” He added that ordinary Americans are missing paychecks but said many have sent him messages that “we agree with you 100 percent.”

Trump’s appearance here highlighted the importance of the organization to him. During the shutdown, he has canceled a ­vacation at his Mar-a-Lago resort in Florida, and aides said he called off a trip to an economic forum in Davos, Switzerland, later this month. Last year, Trump became the first president to address the farmers’ convention since George H.W. Bush.

Steven McCloud, a livestock and small grain farmer from Newton, Kan., said that farmers remain “cautiously optimistic” that the trade war will come to a conclusion that will benefit them in the end. But with the tariffs, along with bad weather, “it’s been a tough year,” he said.

The trade war “is going to cost us a little bit now, but a better trade deal will benefit the next generation to come,” said Bob Schwenke, a corn and soybean farmer from Kentucky. He said his income may take a 5 percent hit in 2018, and if the trade war continues it could be 15 percent this year. Asked how long he would put up with such losses before getting grumpy, he quipped, “I’ve been grumpy all my life.”

The Trump administration has initiated a program to help tariff-damaged farmers that includes about $11 billion in direct cash assistance to farmers — the bulk of which would go to soybean producers — as well as $1 billion to purchase excess supply and distribute it to food banks and nutrition programs.

Without that bailout money, farmers said, their situation would be far more dire.

“If it wasn’t for that, there would be some farmers who were in bad shape,” said Bo Mason, who grows rice, corn and soybeans in Arkansas. An independent voter who once voted for Obama, he voted for Trump in 2016 because “there wasn’t any other choice.” In 2020, he says, he will weigh the Democratic candidate carefully.

Outside the hall, where Toby Keith music boomed, Earl Williams Jr., a Rockford, Ill., corn and soybean farmer who is on the board of directors of the Illinois Farm Bureau, said that the trade war has to end.

“We’ve got to do something. This is killing us in the Midwest,” he said. “We’ve managed to alienate so many of our traditional trading partners.”

But other farmers said that China had it coming — “they’ve manipulated our markets for years,” Mason said — and expressed optimism that trade negotiators would soon reach an agreement.

“I think they will. The problem is China is hardheaded and Trump is a hardhead, too,” said Mason Sickel, who grows rice and soybeans in Arkansas. “Put a pair of those together and it will take a while to resolve the argument.”

During his speech, Trump warned against the dangers of illegal immigration. He also criticized legal immigration programs that aim to reunite families, which he derisively calls “chain migration” — even though first lady Melania Trump’s parents, who this year gained U.S. citizenship, are thought to have first been awarded green cards, allowing them legal permanent residency, through that process.

The Trump administration allowed a one-time increase over the summer of 15,000 H-2B visas for seasonal nonagricultural workers — a 45 percent increase in that category — amid demands from businesses during a period of low unemployment.

Immigrant farmworkers are admitted through a separate H-2A visa program. Trump administration officials have said they are looking at streamlining the rules to offer employers more flexibility.

“It’s going to be easier for them to get in than what they have to go through now,” the president said of those workers, before adding: “I know a lot about the farming world.”

Nakamura reported from Washington.