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


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:

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

Efstef 2 years 2020-09-29T07:10:18-05:00 0 Answers 13 views 0

Leave an answer