Skip to content

14.1 - Nested taxonomy breadcrumbs in wrong order (HTML & Schema) #15173

@Djennez

Description

@Djennez

Continuing from #15071 (comment)

The order of breadcrumbs seems to be wrong when a nested taxonomy is selected as the primary (or only) one. I was able to reproduce this with the normal posts, as well as custom posttypes.

  1. Install 14.1
  2. Enable breadcrumbs and set the taxonomy breadcrumb for posts to be category
  3. Create a post category and 2 child categories
  4. Create a new post and assign the 2 childs and set one of them as primary
  5. Either add the [wpseo_scortcode] to the post, or add it to your theme somewhere, and publish the post
  6. Visit the post on the frontend and notice a wrong breadcrumb order in both the HTML output as well as schema.
  7. Edit the post, removing one of the selected childs so that there is only one selected. Save the post
  8. View the post again, the breadcrumb order is wrong as well

These steps can be reproduced on custom posttypes (like the books from the Yoast Test Helper) as well. Adding more nested layers will keep a wrong order in the breadcrumbs:

Home » Level 1.1 » Level 1 » Level » Boss

Instead of

Home » Level » Level 1 » Level 1.1 » Boss

It also looks like the first visit of a post after resetting the indexables shows the breadcrumbs in the right order. Refreshing the page will mess up the order again. This may be due to the first load of a page using the fallback, and not the indexables, to generate the breadcrumbs?

I got this to work correctly by changing this query:

public function find_ancestors( Indexable $indexable ) {
$ancestors = $this->query()
->where( 'indexable_id', $indexable->id )
->order_by_desc( 'depth' )
->find_many();

To use order_by_asc instead of order_by_desc. But this code does not seem to be changed from 14.0.4 (where this does not happen). So I guess it got sorted downstream and that got broken?
The problem is in the fact that the ancestors get stored in a different order in 14.1. Which is why posts created on 14.0.4 are showing correctly. See the linked PR below.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions