Last active
August 20, 2016 10:32
-
-
Save h1dd3nsn1p3r/f0b06c453b5185ba016654022f97e1fe to your computer and use it in GitHub Desktop.
Adding custom post type support in functions.php file to show custom posts types in category, tags & archives.
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
| /* | |
| display / Show custom post types posts in Archive, tags & categories. | |
| */ | |
| function query_post_type($query) { | |
| if(is_category() || is_tag()) { | |
| $post_type = get_query_var('post_type'); | |
| if($post_type) { | |
| $post_type = $post_type; | |
| } else { | |
| $post_type = array('nav_menu_item','post','custom_posttype1', 'custom_posttype2', 'custom_posttype3', 'custom_posttype4'); | |
| } | |
| $query->set('post_type',$post_type); | |
| return $query; | |
| } | |
| } | |
| add_filter('pre_get_posts', 'query_post_type'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment