admin管理员组文章数量:1328595
In my wordpress theme I created a new custom post type 'books' with 2 taxonomies ('series', 'genres'). when I visit the archive of the cpt 'books' (site/books), I list all the books.
I added a custom frontend filter to get in this archive page books by taxonomy terms by passing an argument to the url with the name of the taxonomy and the terme (like this: site/books/?genres=action). Like a book browser.
But wordpress is by default creating the link for my taxonomies like this (site/genres/action/) and i want it to be "redirected" to the books post type with the taxonomy argument (site/books/?genres=action).
Is it possible to achieve that ? Thank you
Update
Actually I'm using this "workaround" :
// Change url link for term of taxonomies of CPT Book
function cpt_book_term_link_filter( $url, $term, $taxonomy ) {
if ( in_array($taxonomy, get_object_taxonomies('books')) ) {
$url = home_url() . '/books/?'. $taxonomy . '=' . $term->slug;
}
return $url;
}
add_filter( 'term_link', 'cpt_book_term_link_filter', 10, 3 );
With this I edit each taxonomies terms of the Custom Post Type book and change it to link to my Custom Post Type book archive's page.
But I don't think it's the best solution. Because archives page for my taxonomies (books/genres/action, ...) still exist and are used for canonical url in plugins like yoast seo. I can force to redirect them but I don't think its good.
本文标签: Use Custom Post Type archive page for the taxonomies term archive page
版权声明:本文标题:Use Custom Post Type archive page for the taxonomies term archive page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742215408a2434474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论