• Resolved WP CMS Ninja

    (@billiardgreg)


    I have created a taxonomy product_category underneath another cpt products.

    I have exported the code and included it in the theme of the site yet even with a rewrite set with hierarchical turned on it still only allows browsing to sub-categories under the main slug and under main slug/parent/child URL structure.

      $labels = [
        "name" => __( "Product category", "custom-post-type-ui" ),
        "singular_name" => __( "Product category", "custom-post-type-ui" ),
      ];
    
      $args = [
        "label" => __( "Product category", "custom-post-type-ui" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => false,
        "rewrite" => [  'slug' => 'product-category',
                        'with_front' => true,
                        'hierarchical' => true,
                      ],
        "show_admin_column" => true,
        "show_in_rest" => false,
        "show_tagcloud" => true,
        "rest_base" => "product_category",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
        "show_in_graphql" => false,
      ];
      register_taxonomy( "product_category", [ "product" ], $args );

    I have even tried it using CPT UI in a developer environment in the attempt to see if there is something else happening and I can’t seem to get taxonomies that hierarchical to work.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Trying to make sure I’m comprehending the desired permalinks here.

    You have a product_category taxonomy, with a rewrite slug of product-category.

    You’re getting this structure?
    mydomain.com/product-category/container/bottle/andmydomain.com/product-category/container/can/` and similar?

    When you’re wanting this structure?
    mydomain.com/container/bottle/andmydomain.com/container/can/` and similar?

    Or is it possible that by “not work” you’re referring more to maybe those permalinks are working fine, but no content is being shown at them?

    Thread Starter WP CMS Ninja

    (@billiardgreg)

    The structure that I am wanting is as followed based on your example:
    mydomain.com/product-category/container/bottle/

    Right now the only way I can get to it is via this URL:
    mydomain.com/product-category/bottle/

    Where bottle is a sub-category of parent container.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hmm, according to posts like https://wordpress.stackexchange.com/questions/155319/how-to-include-parent-terms-in-hierarchical-taxonomy-urls, we have everything in place and as it should be. However, I was able to reproduce where /product-category/child works, but /product-category/parent/child does not.

    Using the Query Monitor plugin, it seems that the parent/child version is getting interpreted as one term, not 2.

    taxonomy=product_category&term=parent%2Fchild
    

    The %2f is an encoded /

    That said, setting query var to true looks like it’s working for me, so that may be the key detail going on here. Is there reason you need query var to be set to false?

    Thread Starter WP CMS Ninja

    (@billiardgreg)

    No reason for query_var to be set to false, I changed it to be set to true in the attempt to get the /product-category/parent/child working but it is still throwing a 404. but /product-category/child does work.

      $labels = [
        "name" => __( "Product category", "custom-post-type-ui" ),
        "singular_name" => __( "Product category", "custom-post-type-ui" ),
      ];
    
      $args = [
        "label" => __( "Product category", "custom-post-type-ui" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [  'slug' => 'product-category',
                        'with_front' => true,
                        'hierarchical' => true,
                        // 'hierarchical' => false,
                      ],
        "show_admin_column" => true,
        "show_in_rest" => false,
        "show_tagcloud" => true,
        "rest_base" => "product_category",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
        "show_in_graphql" => false,
      ];
      register_taxonomy( "product_category", [ "product" ], $args );

    And I did attempt to clear the permalink cache.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What permalink rules are you using? Something besides “post name” for the radio button options?

    Thread Starter WP CMS Ninja

    (@billiardgreg)

    When you say Post Name for the radio buttons option, this is a hierarchal taxonomy of product categories. There is a main Product post type that can have these categories assigned to it. Not sure what you mean tbh.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What I meant is basically which selection did you make when you visit Settings > Permalinks in your WP admin. Wanting to make sure I am using matching permalinks.

    /wp-admin/options-permalink.php

    Thread Starter WP CMS Ninja

    (@billiardgreg)

    I have “Post Name” selected.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    And even with that, the permalinks with both parent and child terms aren’t working at this point?

    I have the same permalinks settings and it was for me, but it’s possible something else in your install may still be interfering.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Taxonomy Permalink Issue w/ Sub-Cats’ is closed to new replies.