Skip to content

Navigation Link block: taxonomy terms added via the Navigation builder are saved with kind:"post-type", then get_url() resolves the term ID as a post ID and renders a wrong URL on the front end" — or even a shortened version like "Navigation builder saves taxonomy terms as post-type links; front end renders wrong URLs #1343

Description

@theorigamifox

Navigation Link block: taxonomy terms added via the Navigation builder are saved with kind:"post-type", then get_url() resolves the term ID as a post ID and renders a wrong URL on the front end

Environment

  • Kadence Blocks 3.7.9.1 (also confirmed in current trunk)
  • Kadence Blocks Pro 2.8.17, Kadence Theme, WooCommerce
  • WordPress 7.1, PHP 8.2.33

Summary

Product category links added through the Advanced Navigation builder's "select existing items" browser render broken URLs on the front end (for example /144/ or /?p=94 instead of /product-category/accessories/), while the editor shows the correct URL. Two separate issues combine to cause this.

Steps to reproduce

  1. WooCommerce site with product categories. Note a category's term ID (for example Accessories, term ID 144).
  2. Add an Advanced Navigation block (or edit a navigation in the builder). Use the "select existing items" browser to add that product category as a nav item.
  3. Check the saved block markup. The item is stored as:
    {"label":"Accessories","id":144,"url":"https://example.com/product-category/accessories/","kind":"post-type"}
    Note: kind is post-type for a taxonomy term, and there is no type attribute.
  4. View any page that renders this navigation on the front end while a post row with ID 144 exists in an odd state (drafts, auto-drafts of CPTs such as kadence_navigation itself, etc. - on our site the colliding IDs were Kadence's own auto-draft navigation posts).
  5. The rendered href is not the stored URL. We observed /144/, /?p=94, /?p=20, and a wrong page URL, all 404s.

Root cause

Issue 1 (save side): In blocks-navigation.js (src for dist/blocks-navigation.js), the "add existing items" handlers create nav-link blocks with kind: "post-type" hardcoded. The taxonomy variant maps terms as:

createBlock('kadence/navigation-link', {
    label: e.name,
    url: e.link,
    id: e.id,        // term ID
    type: e.type,    // terms have no .type, so this is undefined and gets dropped
    kind: 'post-type' // hardcoded, wrong for terms
});

So a term is stored with its term ID labelled as a post-type link, with no type.

Issue 2 (render side): includes/blocks/class-kadence-blocks-navigation-link-block.php, get_url() (around line 871): when kind === 'post-type' and id is set (disableLink defaults to false), it calls get_permalink( $attributes['id'] ) and returns it whenever truthy, silently replacing the stored URL. There is no get_term_link() branch anywhere in the file, and no check that the ID belongs to a real, published post. A term ID therefore resolves against whatever unrelated post row shares that number.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions