Ever since the very first games, part of what made the Pokemon games so fun is the ability to battle and trade with other players like yourself. Of course, this hasn't changed in Sun and Moon.
There are two ways you can battle and trade--locally with nearby players or via the Internet.
If you want to battle or trade with somebody nearby, the quickest way is for both of you to select the Quick Link option from the menu (by pressing the X button while on the field).
You will both be prompted to tap the bottom screen or hold the A button until you're wirelessly connected with the other player. It shouldn't take more than several seconds, so just be patient!
If the connection is successful, one of you will be able to decide whether to have a Link Battle (Single Battle), Link Battle (Double Battle), Link Trade or defer the decision to the other player.
The other method, which is useful if there are many, many players around is to access the Festival Plaza from the menu instead. Once inside, tap the big "Battle" or "Trade" buttons on the bottom screen. Then select either "Link Battle" or "Link Trade".
If selecting "Link Battle", there will be options to have a Single Battle, Double Battle, Multi Battle or Battle Royal. After making your choice, the game will bring up the Guest List for the plaza. This will show all nearby players, plus others you've recently met.
From here, select a nearby player whose name is solid black and not greyed out. That player will receive a battle or trade request from you, which they can choose to accept or not. By default, requests last for 30 seconds, after which they're automatically declined.
If you're having difficulties finding a particular player in Festival Plaza, you can try to register them as a 3DS friend beforehand. Afterwards, that player will have "Friend List" next to their name in the plaza Guest List.
If you still cannot find that friend, try pressing the X button to update the Guest List. Finally, make sure that friend has wireless communications enabled and that they're not connected to the Internet.
To play with somebody online, you need to access the Festival Plaza from the menu. Afterwards, tap the most bottom-right icon on the bottom screen to connect to the Internet. You will need to save your game.
Connecting Your 3DS (or 2DS) Online
To connect online, you must have a compatible wireless access point (for example, a router). From your 3DS (or 2DS) Home Menu, go to the "System Settings" application. Choose "Internet Settings", then "Connection Settings".
Next, tap "New Connection", followed by "Manual Setup" when asked. Finally, go to "Search for Access Point". With luck, your access point should appear in the list. Select it and enter your details, then perform a connection test to see if it works.
If you're unsure about anything, don't be shy and ask somebody who might know!
Once connected, just like playing locally, tap the big "Battle" or "Trade" buttons on the bottom screen. If you want a straightforward battle or trade with another player you know, select the "Link Battle" or "Link Trade" options as before.
When the Guest List appears, this time the names of online players are solid black, while those who are busy or don't want to play are greyed out. From here, search for the player you want to battle or trade. Of course, that player must be online like you.
While connected online, if you want to do something a bit more fancy, there are some other options available when selecting "Battle" or "Trade".
Visit the Battle Spot: Compete against random players from across the globe in free battles, rating battles or online competitions, etc. A Pokemon Global Link account may be required.
Pokemon Global Link
This is an official website run by The Pokemon Company, where you can register an account and register your Pokemon Sun or Moon game to enjoy more online activities. You can register an account online using a computer or smart device, etc.
To register your game, go inside the castle in the middle of Festival Plaza, then inspect the PC on the desk immediately to the right when you enter. Choose the "Game Sync" option and connect to the Internet (if you aren't already connected).
GTS: Short for "Global Trade Station". This allows you to upload a Pokemon for trade or search for other players' uploaded Pokemon. Useful if you don't know any players to trade.
We're not going to sugar-coat it; the GTS can be headache-inducing for getting the Pokemon you want. Very often, other players will ask for something ridiculous--or outright impossible--for their Pokemon. For instance, you can dismiss most requests for full evolved Pokemon below Level 10.
Additionally, if you seek to trade for a Pokemon that evolves after trading, make sure it is not holding an Everstone! It's recommended you avoid seeking Pokemon altogether; upload your own Pokemon and make a reasonable request. Sigh, if only more people were like you...
Wonder Trade: This sets up an instant trade with a random player from anywhere in the world. See the next page for more information. Again, useful if you've got no friends or you're looking for a surprise.