The player resists the urge, as would anyone. When the situation becomes imperative, the player goes to the nearest toilet. At the professional league level, there should be one very close by under the grandstand. The player leaves, with a word to a teammate and to an official.
The Laws of the Game, of course, make it cautionable misconduct for a player to leave the field of play, but this is intended to punish disregard of the spatial limits of the field, or unsporting departure from the field to put an opponent offside or to unsportingly quit the game. A Referee would treat leaving to answer an urgent call of nature as he would treat a need to remedy an equipment or uniform problem, allowing the player to leave the match. The player would report his return to the Referee or another official, the player’s uniform and equipment would be checked (NOT what you might be thinking!), and the Referee would beckon the player to re-enter as soon as possible, even during play, as long as the reentry causes no unfair disadvantage to the opponents.
Relieving oneself on the field would be highly unsporting, causing a nuisance or unpleasantness for others, perhaps making that location on the field or ground unplayable, if only temporarily. Recreational players occasionally find themselves unable to find a sanitary convenience near the field, and it may happen that a player might need to step off the field behind the goal to “kneel in prayer” (sometimes said to be “dribbling behind the goal”) and relieve a minor need. Defecation on or near the field (a la Lineker), or in a nearby area, would be highly offensive to the Game and to the public, and once the offense was committed, unless the event was severely involuntary, a player might be cautioned for unsporting behavior.