admin管理员组文章数量:1125596
I have a custom post type (url), and a custom taxonomy term (url-category) for this post type.
The archive page for this custom post type works fine.
The taxonomy term archive claims there are no posts for the terms, even when there are. On these taxonomy term archive pages, the function get_queried_object()
returns something like this (details replaced with placeholders):
WP_Term Object ( [term_id] => 15229 [name] => -- title -- [slug] => -- slug -- [term_group] => 0 [term_taxonomy_id] => 15229 [taxonomy] => url-category [description] => -- desc -- [parent] => 0 [count] => 38 [filter] => raw )
However, have_posts()
immediately after get_queried_object()
returns false
.
In the Wordpress backend, filtering the post type on the taxonomy term works as expected, showing the matching posts.
How to begin to troubleshoot this?
Updates as per questions in the comments:
I use template files for archive-url.php and taxonomy-url-category.php. But, reverting to the default template files makes no difference.
Flushing the permalinks makes no difference.
I use the pre_get_posts hook to update my queries. But, turning this off makes no difference for what happens above.
Adding the post type as a query string parameter does make a difference. The URL
/url-category/category/?post_type=url
uses thearchive-url.php
template file, but shows only the posts from the category in question.
So, there's some progress there. But I don't understand what's happening.
Another update:
Adding the following to the code that runs on the hook pre_get_posts
makes the taxonomy terms show their content:
if ( is_tax( 'url-category' ) ) {
$query->set( "post_type", "url" );
}
Still don't know why this is necessary. :(
本文标签: Taxonomy term archive claims there are no postsbut there are How to resolve
版权声明:本文标题:Taxonomy term archive claims there are no posts, but there are. How to resolve? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736661232a1946426.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论