admin管理员组文章数量:1023077
I’ve taken over website from another developer and they used a plugin to generate a custom post types. The plugin is no longer maintained and sometimes courses an error 505 when try and load the plugins admin page. The front end site works fine. I also don't like having out of date plugins because of the security risk. ' I previously asked a question related to this issue which was solved about getting the properties of a custom post type created by a plugin so they I could re make it using register_post_type(). That was solved by Qaisar Feroz with get_post_type_object().
I have now recreated the post types and everything works fine in the back end. I can see all my posts that are custom post types. The only remaining problem is that one of the post types uses the standard Wordpress category as its taxonomy. Custom post types are not showing up on the category pages like they used to, if I was making the site from scratch I would use a custom taxonomy but all the posts and their links to the categories already exist. I have read that if a custom post type uses Wordpress' standard taxonomy's: tags & category you have to take extra steps for the custom post types to show up on the category archive pages. I tried several code snippets but every-time I use something like the one below my custom post types will display on the category page but none of my menus will display in the header or the footer. Its must be possible as it all worked fine with the plugin (Toolset Types)
My custom post type is called 'product'.
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', 'product'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
I’ve taken over website from another developer and they used a plugin to generate a custom post types. The plugin is no longer maintained and sometimes courses an error 505 when try and load the plugins admin page. The front end site works fine. I also don't like having out of date plugins because of the security risk. ' I previously asked a question related to this issue which was solved about getting the properties of a custom post type created by a plugin so they I could re make it using register_post_type(). That was solved by Qaisar Feroz with get_post_type_object().
I have now recreated the post types and everything works fine in the back end. I can see all my posts that are custom post types. The only remaining problem is that one of the post types uses the standard Wordpress category as its taxonomy. Custom post types are not showing up on the category pages like they used to, if I was making the site from scratch I would use a custom taxonomy but all the posts and their links to the categories already exist. I have read that if a custom post type uses Wordpress' standard taxonomy's: tags & category you have to take extra steps for the custom post types to show up on the category archive pages. I tried several code snippets but every-time I use something like the one below my custom post types will display on the category page but none of my menus will display in the header or the footer. Its must be possible as it all worked fine with the plugin (Toolset Types)
My custom post type is called 'product'.
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', 'product'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
Share
Improve this question
asked May 10, 2019 at 14:33
lomokevlomokev
1831 gold badge2 silver badges10 bronze badges
1 Answer
Reset to default 0You don't need to return $query
it is passed by reference.Have a look at the codex
The return
statement might be shortcircuiting the page load. Try removing it.
I’ve taken over website from another developer and they used a plugin to generate a custom post types. The plugin is no longer maintained and sometimes courses an error 505 when try and load the plugins admin page. The front end site works fine. I also don't like having out of date plugins because of the security risk. ' I previously asked a question related to this issue which was solved about getting the properties of a custom post type created by a plugin so they I could re make it using register_post_type(). That was solved by Qaisar Feroz with get_post_type_object().
I have now recreated the post types and everything works fine in the back end. I can see all my posts that are custom post types. The only remaining problem is that one of the post types uses the standard Wordpress category as its taxonomy. Custom post types are not showing up on the category pages like they used to, if I was making the site from scratch I would use a custom taxonomy but all the posts and their links to the categories already exist. I have read that if a custom post type uses Wordpress' standard taxonomy's: tags & category you have to take extra steps for the custom post types to show up on the category archive pages. I tried several code snippets but every-time I use something like the one below my custom post types will display on the category page but none of my menus will display in the header or the footer. Its must be possible as it all worked fine with the plugin (Toolset Types)
My custom post type is called 'product'.
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', 'product'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
I’ve taken over website from another developer and they used a plugin to generate a custom post types. The plugin is no longer maintained and sometimes courses an error 505 when try and load the plugins admin page. The front end site works fine. I also don't like having out of date plugins because of the security risk. ' I previously asked a question related to this issue which was solved about getting the properties of a custom post type created by a plugin so they I could re make it using register_post_type(). That was solved by Qaisar Feroz with get_post_type_object().
I have now recreated the post types and everything works fine in the back end. I can see all my posts that are custom post types. The only remaining problem is that one of the post types uses the standard Wordpress category as its taxonomy. Custom post types are not showing up on the category pages like they used to, if I was making the site from scratch I would use a custom taxonomy but all the posts and their links to the categories already exist. I have read that if a custom post type uses Wordpress' standard taxonomy's: tags & category you have to take extra steps for the custom post types to show up on the category archive pages. I tried several code snippets but every-time I use something like the one below my custom post types will display on the category page but none of my menus will display in the header or the footer. Its must be possible as it all worked fine with the plugin (Toolset Types)
My custom post type is called 'product'.
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', 'product'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
Share
Improve this question
asked May 10, 2019 at 14:33
lomokevlomokev
1831 gold badge2 silver badges10 bronze badges
1 Answer
Reset to default 0You don't need to return $query
it is passed by reference.Have a look at the codex
The return
statement might be shortcircuiting the page load. Try removing it.
本文标签: taxonomyCustom post types not showing on the standard Wordpress Category page
版权声明:本文标题:taxonomy - Custom post types not showing on the standard Wordpress Category page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745505706a2153594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论