Last active
March 2, 2016 15:10
-
-
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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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