By: Prem Tiwari | Last Updated:
This is very helpful code snippets to exclude the custom posts from WordPress search algorithm. If you are using custom post types on your WordPress sites and don’t want to display that post in your search results, then use the below code.
Copy the below code and add at the end of the functions.php file.
$args = array(
'exclude_from_search' => false, // the important line here!
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt','comments')
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari