Skip to content

Instantly share code, notes, and snippets.

@tradesouthwest
Created February 22, 2019 03:55
Show Gist options
  • Save tradesouthwest/248574254c81e882249e97039a661c64 to your computer and use it in GitHub Desktop.
Save tradesouthwest/248574254c81e882249e97039a661c64 to your computer and use it in GitHub Desktop.
modifies the main WordPress query to include an array of post types
<?php
/**
* This function modifies the main WordPress query to include an array of
* post types instead of the default 'post' post type.
*
* @param object $query The original query.
* @return object $query The amended query.
*/
function trunkline_custom_search_query( $query ) {
if ($query->is_search) {
$query->set( 'post_type', array( 'post', 'job_listing', 'products', 'page' ) );
}
return $query;
}
add_filter( 'pre_get_posts', 'trunkline_custom_search_query');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment