Home » WordPress » Display Only Post Search Results on Your WordPress

Display Only Post Search Results on Your WordPress

If you like to display only post search results on your WordPress website, then here we have a simple solution to filter only post results on the search page. The WordPress search results are developed with default to get all the search results. To avoid unwanted results let us filter only the post results using a simple function.

Use the below code in your functions.php and you get only the post results on the search page.

In the above code, we set a simple search query function to filter the results. You also change the post type in your function if you are used Custom Post Type.

Display Post Search Results Based on Users

To customized post results based on users let us declare simple condition before the post search function. The below code will exclude post search result only for the admin.

In the above code, we used the same function but with excluding admin using IF condition. You can change the user roles as per your requirement.

Conclusion:

I hope you enjoyed the article by displaying only post search results on your WordPress site. If you have any queries about this topic let me know in the comment section and if you loved this article share it with your friends.

Was this article helpful?

Yes No
×

How can we improve it?

×

We appreciate your helpul feedback!

Your answer will be used to improve our content. The more feedback you give us, the better our pages can be.

Follow us on social media:

Facebook Pinterest

Mraj

Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts.

One thought on “Display Only Post Search Results on Your WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top