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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?php add_action('init', 'codex_custom_init'); function codex_custom_init() { $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') ); register_post_type('book',$args); } ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Exclude a custom post type from search, wordpress custom post, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials for beginners