Last active
November 23, 2017 12:07
-
-
Save IacopoC/54c75bbe3bd714317ddf15c36be0e6df to your computer and use it in GitHub Desktop.
Allow cpt in category list archive in wordpress
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
<?php | |
// Allow cpt in category list | |
add_filter('pre_get_posts', 'query_post_type'); | |
function query_post_type($query) { | |
if( is_category() ) { | |
$post_type = get_query_var('post_type'); | |
if($post_type) | |
$post_type = $post_type; | |
else | |
$post_type = array('nav_menu_item', 'post', 'name_of_post_type'); // don't forget nav_menu_item to allow menus to work! | |
$query->set('post_type',$post_type); | |
return $query; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment