Skip to content

Instantly share code, notes, and snippets.

@pascalmaddin
Last active March 2, 2016 15:10
Show Gist options
  • Save pascalmaddin/14d0429a7fca1d1bdb9d to your computer and use it in GitHub Desktop.
Save pascalmaddin/14d0429a7fca1d1bdb9d to your computer and use it in GitHub Desktop.
I wanted the custom post type to show up on the regular author/search results page. Here's what I came up with in case anyone else is looking:
/*
* I wanted the custom post type to show up on the regular author page. Here's what I came up with in case anyone else is looking:
*/
add_filter('posts_where', 'include_for_author');
function include_for_author($where){
if(is_author())
$where = str_replace(".post_type = 'post'", ".post_type in ('post', 'custom_post_type')", $where);
return $where;
}
/*
* I wanted the custom post type to show up on the regular search results page. Here's what I came up with in case anyone else is looking:
*/
function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'custom_post_type'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment