最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

After 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论