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

wordpress.stackexchange https://wordpress.stackexchange.com/questions/377028

Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top