Include or exclude custom post types in wordpress search result

Defining post types in search query allows you to include or exclude the custom post types in wordpress search result. Just add this function to functions.php

// MAKE CUSTOM POST TYPES SEARCHABLE
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'site','plugin', 'theme','person' ));
}
return $query;
}
add_filter( 'the_search_query', 'searchAll' );
$query->set( 'post_type', array( 'site','plugin', 'theme','person' )); we can add or remove the post-types to be searched. Short but effective.

Comments

Popular posts from this blog

Send email from xampp localhost

Modify item price in cart after placing order using sales_quote_add_item

Convert long url to short url using tinyurl api