How to Search only Posts or Pages in WordPress

The WordPress search function by default will display all published pages and posts in the search results. While typically this setup is most ideal, there may however come a time when you only want to display your WordPress website’s posts or pages in the search...