Category Archives: PHP

How To Limit Search Results For Specific Post Types in WordPress

I was working on a site where I need to limit the search to post types only. Wondering for a while I figured out how to limit search results for specific post types in WordPress. To do so you have to add a function on your functions.php.

The above code limits the search to post only. But you can change it according to your needs. To do so you have to make changes on line:

To add pages to search along with post:

You can add values to array like above to limit search results.

Email address validation using PHP

Most people use regular expression (regex) for email validation. But there is no simple regex for validating email. The expression with the best score is, regex by Michael Rushton.

PHP’s filter_var(), is based on the above regex. If you are using PHP 5 or later then you can use this handy function for validating an email.

Below is the syntax for email validation