Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Add Resource custom post type to default query for category archive
- add_filter( 'pre_get_posts', 'add_resource_post_type' );
- function add_resource_post_type( $query ) {
- if ( is_category() || !is_admin() && $query->is_category_page ) {
- if(!is_array($query->query_vars['post_type'])) {
- $postTypes = array($query->query_vars['post_type']);
- } else {
- $postTypes = $query->query_vars['post_type'];
- }
- if(!in_array('resources',$postTypes)) {
- if(count($postTypes) == 1 && trim($postTypes[0]) == "") {
- $postTypes[] = 'post';
- $postTypes[] = 'resources';
- } else {
- $postTypes[] = 'resources';
- }
- }
- $query->query_vars['post_type'] = $postTypes;
- // print_r($postTypes);
- }
- return $query;
- }
Advertisement
Add Comment
Please, Sign In to add comment