The first part of the pig farm is the pigs. With a hammer, destroy as many pig houses as you can. Although pig houses can be encountered in any area on occasion, the best way to find a lot of pig houses is by finding the Pig King's village, which can be found in the Deciduous Forest. Pigs will not be hostile if their home is destroyed.
Once you have destroyed as many pig houses as you desire, find a good location to build your farm. The ideal spot is somewhat close to your base, but not too close. Remember to distance it from any sinkholes or spider dens to avoid the pigs getting distracted. Build a small pen of stone walls with a single pig skin in the middle, and some pig houses surrounding it. When day comes, the pigs will come out of their houses and try to eat the pig skin by walking into the wall. They will continue this, even at night.
Wait for a full moon to harvest the pig farm. Equip a spear and log suit if you do not already have a ham bat. When the pigs turn into Werepigs, attack and kill them one by one. Once you have killed one, craft a ham bat if you were using a spear, and use it on the rest of the pigs.
Continue killing the werepigs until they are all dead or day comes, whichever is first. Afterwards, use the pig skin to craft some more pig houses and expand the farm.