admin管理员组文章数量:1318156
I will try to explain the problem that occurred. Useful info: The site is up to date (plugins, WordPress, PHP). I use a premium theme and to do the translation I use the WPML.
I have applied 2 functions in my child theme, that let me use categorize my pages.
I am aware that this functionality is only for the blog system of WordPress, but currently is something that I can use to add multiple pages under one category and get the results.
The code is this:
<?php
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
?>
The problem begins in the translated version of the site. As I referred to the top, I use WPML to make the translation. So when I change the site in its English version and do a wp query to fetch some result for a specific category, I have multiple entries that appear in the breadcrumb.
For example.
Home > category1 > category1 > category1 > category1
I noticed that the category1 duplication is based on how many results the query will fetch.
In other words, if I have category1 applied in 9 pages, then the breadcrumb will appear like this:
Home > category1 > category1 > category1 > category1 > category1 > category1 > category1 > category1 > category1.
I try to figure out a way to debug it. I also contacted the theme author and the WPML but I see a ping-pong game, between the responsibility.
So I try to debug it myself if I can.
I will try to explain the problem that occurred. Useful info: The site is up to date (plugins, WordPress, PHP). I use a premium theme and to do the translation I use the WPML.
I have applied 2 functions in my child theme, that let me use categorize my pages.
I am aware that this functionality is only for the blog system of WordPress, but currently is something that I can use to add multiple pages under one category and get the results.
The code is this:
<?php
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
?>
The problem begins in the translated version of the site. As I referred to the top, I use WPML to make the translation. So when I change the site in its English version and do a wp query to fetch some result for a specific category, I have multiple entries that appear in the breadcrumb.
For example.
Home > category1 > category1 > category1 > category1
I noticed that the category1 duplication is based on how many results the query will fetch.
In other words, if I have category1 applied in 9 pages, then the breadcrumb will appear like this:
Home > category1 > category1 > category1 > category1 > category1 > category1 > category1 > category1 > category1.
I try to figure out a way to debug it. I also contacted the theme author and the WPML but I see a ping-pong game, between the responsibility.
So I try to debug it myself if I can.
Share Improve this question asked Sep 29, 2020 at 11:44 EfstefEfstef 115 bronze badges1 Answer
Reset to default 0After some time with WPML support and with some debugging/digging in the theme's core files, I found where the breadcrumb was created. I pointed this out in the support and to also add the taxonomy on pages also in their filtered queries.
I was using default WordPress queries and I was aware that taxonomies on pages are not the default use in WordPress. Also, there was a conflict with WPML and the table "taxonomy" restructure.
If anyone else ever comes across this problem or similar, you will have to update your WPML version to 4.4.4 and above.
本文标签:
版权声明:本文标题:functions - Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742041518a2417567.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论