CPT UI Category URL
-
Hello guys,
I am trying to solve the following problem and hope you may help me.
We already build several custom post types manually (writing the code ourselves) before, which you can all see in the navigation of our page https://omkb.de. “Videos” /videos/, “Reviews” /reviews/, “Speaker” /speaker/ and “Jobs” /jobs/.
To prevent having to write code by ourselves and shutting down the entire website when someone does not work accordingly, we decided to build the next custom post types /company/ an /events/ (both are not finished yet and therefore not linked in the navigation yet) with CPT UI, which worked so far.
From the url side, I would like to end up with something similar to what we build manually:
/events/category/categoryname OR
/events/categorynameI worked alot with the settings already and tried to set a custom rewrite rule, but nothing worked out.
No matter what I do, the category page (see this test category for example https://omkb.de/events/testkategorie/) always shows an 404 error.
When trying to apply my elementor template to the category page, I can not select the “Events Kategorien” I build in CPT UI neither.
Hope you can help me making our custom taxonomy accessible.
Looking forward to your reply!
Regards
ThomasThe page I need help with: [log in to see the link]
-
Before I attempt too much, can you answer if you have these permalink structure working already for other post types and whatnot or if these are brand new structures you’re attempting to create for all of them
/post-type-slug/category-taxonomy-slug/category-term/
/post-type-slug/category-taxonomy-slug/category-term/My bets are high that
/events/testkategorie/
is being interpreted as an event post and not a category term.Hi Michael,
thank you for your reply!
Yes, we have this permalink structure working for other post types already.
See:
https://omkb.de/videos/category/growth-hacking/
https://omkb.de/reviews/category/zeiterfassung/
https://omkb.de/jobs/category/online-marketing/
https://omkb.de/speaker/category/display-advertising/All of them have been created in the code “manually” (we ofc copied the code and made our changes) though.
Events is the first custom post type we created with the Custom Post Type UI plugin.
It’s fairly possible testkategorie is being interpreted as a post instead of a category. How to change this/put the /category/ term in between though?
Looking forward to your reply!
Thank you!
I’m legitimately curious how/why things are working with those previous ones, and not one registered with CPTUI, outside of perhaps order of loading. For example we’re getting our callbacks to register the post types in earlier, and that’s somehow not working with what is working.
I assume there’s code being used to make this work for the other post types, and perhaps that just needs to be amended to do the same with the new post types. Very likely not a case of “it’d just work out of box with the new ones”. Other parts need updated.
Worth checking around for.
Hi Michael,
it’s monday an I am back at work. ??
Well, it’s not like the Custom Post Types created with your plugin are not working at all. I only struggle with the category slug and later applying the elementor template to it.
For the reviews (just double checked, this one is solved with your plugin as well), the “Custom Title Slug” is “reviews/category” which works just fine. But if I use something like that for Events (“events/category”) or Company (“company/category”), I do net get the extra hierarchie in.
I didn’t mentally stumble onto any answers myself over the weekend, so I don’t know what to suggest at this point outside of what’s already been mentioned, which is comparing working post types+category permalinks to ones that aren’t working, and what extra code was added to apparently make them work.
Hello Michael,
to help you help me a little further, I just copied the code we used to use to declare a new custom post type manually.
Maybe that helps:
/* Post Type Lexikon - Start */ function create_post_type_lexikon(){ $labels = array( 'name' => _x( 'Lexikon', 'Post Type General Name', 'hello-elementor' ), 'singular_name' => _x( 'Lexikon', 'Post Type Singular Name', 'hello-elementor' ), 'menu_name' => __( 'Lexikon', 'hello-elementor' ), 'parent_item_colon' => __( 'Parent Lexikon', 'hello-elementor' ), 'all_items' => __( 'All Lexikon', 'hello-elementor' ), 'view_item' => __( 'View Lexikon', 'hello-elementor' ), 'add_new_item' => __( 'Add New Lexikon', 'hello-elementor' ), 'add_new' => __( 'Add New', 'hello-elementor' ), 'edit_item' => __( 'Edit Lexikon', 'hello-elementor' ), 'update_item' => __( 'Update Lexikon', 'hello-elementor' ), 'search_items' => __( 'Search Lexikon', 'hello-elementor' ), 'not_found' => __( 'Not Found', 'hello-elementor' ), 'not_found_in_trash' => __( 'Not found in Trash', 'hello-elementor' ), ); $args = array( 'label' => __( 'lexikon', 'hello-elementor' ), 'description' => __( 'Lexikon of OMKB', 'hello-elementor' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ), 'taxonomies' => array( 'lexikon_categories' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', 'show_in_rest' => true, 'support' => array('title', 'editor', 'thumbnail'), 'rewrite' => array('slug' => 'lexikon'), ); register_post_type('lexikon', $args); } function create_lexikon_hierarchical_taxonomy() { $labels = array( 'name' => _x( 'Lexikon Kategorien', 'taxonomy general name' ), 'singular_name' => _x( 'Kategorie', 'taxonomy singular name' ), 'search_items' => __( 'Kategorien durchsuchen' ), 'all_items' => __( 'Alle Kategorien' ), 'parent_item' => __( 'übergeordnete Kategorie' ), 'parent_item_colon' => __( 'übergeordnete Kategorie:' ), 'edit_item' => __( 'Kategorie bearbeiten' ), 'update_item' => __( 'Kategorie aktualisieren' ), 'add_new_item' => __( 'Kategorie erstellen' ), 'new_item_name' => __( 'Neuer Kategorie Name' ), 'menu_name' => __( 'Kategorien' ), ); register_taxonomy('lexikon_categories',array('lexikon'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_in_rest' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'lexikon/category/' ), )); } add_action('init', 'create_post_type_lexikon'); add_action('init', 'create_lexikon_hierarchical_taxonomy', 0 ); /* Post Type Lexikon - Ende */
The only thing standing out to me as “abnormal” to a sense, is this part from the taxonomy registration:
'rewrite' => array( 'slug' => 'lexikon/category/' ),
Basically you’re prefixing the post type slug in the rewrite value for the taxonomy.
Hi Michael,
I just tried to add “events/category/” as custom slug (the field further down in CPTUI), but it did not help.
In the next step, I tried to delete and re-create the category (maybe the slug changes only take effect for later added categories), but that did not work neither.
What I noticed: When I want to add a new category from within an events post, 1. the event category is not added (I will not be able to see it), and 2. a new events post is added as “Draft” with no title and no content.
Did I miss-configure something?
Looking forward to your reply!
Regards
ThomasUnfortunately I can not post a screenshot here (or at least, I do not know how to).
When trying to apply my category template to the created category, it does not show, which makes we wonder if the category is properly set up.
On working and functional categories, I see “Name Kategorie”, but with Events and Companys, I only get “Events” and “Companys”.
So, I checked which settings I have set for “Reviews” (which works) and compared them to “Events” and “Companys”. Pretty much the same despite from the fact that the slug at the very top is the same as the slug further down, extended with /category/.
I also checked regarding hirarchical false and true and did not notice a difference.
What I notice meanwhile: If I have set hirarchical to true (meaning I want a category behaviour), I can not select from the list of already available categorys. Instead, everytime I hit enter after I typed a category name, a new, empty events entry is created.
Pretty strage, and unfortunately, I still did no progress…
As I further checked regarding taxonomies in WordPress, I found Answer 1 here https://wordpress.stackexchange.com/questions/691/the-difference-between-hierarchical-and-non-hierarchical-taxonomies to be pretty useful.
As I red this, I checked the “Registered Post Types and Taxonomies” tab of CPTUI and found that the taxonomie I created for Events is not registered/not listed here.
So, in case I am right, there might be a bug in the plugin.
But as I spammed a lot of posts now, I will give you time to read through and reply to me. ??
If we’re being honest, the
'rewrite' => array( 'slug' => 'lexikon/category/' ),
hack is not something I’m a fan of, because it’s forcing the post type slug into the taxonomy rewrite. Technically forcing itself in places it shouldn’t be. The rewrite fields are meant for just the portions between/
characters in the url. For example if you wanted “category” to be “cat” instead.The tragedy in my mind is that at least at times, it still ends up working.
I suspect you’d need to just mimic the same rewrite value for the other post type/taxonomy structures you’re looking for, but I haven’t tried it out and you’ve tried at least some stuff.
Regarding the “Registered…” page, if it’s not listed there, it’s not part of our saved options somehow, as we just read directly from our two option rows that store everything. Have you confirmed that the missing item is also not shown when clicking to the “Edit Taxonomies” tab and checking the dropdown? It may be named differently depending on the labels used, as we use that instead of the slug.
Hi Michael,
if I wanted “cat” instead of “category” in the slug, why would someone write something else in?^^ As far as I can see, filling the additional field is useful if you want to add additional things because you can not use / in the first slug field.
I will try to adapt the other taxonomies as close to the working one as possible.
To clarify for you:
We got the custom post types Events, Company, Lexikon etc. in the very first menu “Add/Edit Content Type” (should be the translation, we use the Plugin in german). They are named (and shown in the dropdown) exactly the same.Note:
The corresponding category/taxonomy (Events => Event Kategorien) is NOT checked at the very bottom. I noticed this is not the case for a CPT that is working, so I did not do it here.What confuses me:
These checkboxes exist for both, the definition of the custom post type (very bottom) AND the definition of the category/taxonomy (very top).Is there a reason for it and might that be the reason somehow? Why can I/do I have to check “Event Kategorien” (event categories) as taxonomy for “Events” AND later on be able to check “Events” as CPT for “Event Kategorien”? Is it necessary to check these boxes vice versa to make it work or what is the reason for it?
In the second menu, the one where I can edit taxonomies, we got “Events Kategorien” and “Company Kategorien” in the drop down besides from a few others which are not interesting right now I guess.
So far, everything looks fine to me.
I just double checked the “Registered…” page and here, everything seems to look fine too. Dunno, I feel like this was different yesterday.
Though:
If I am in an entry on my custom post type events (any event) I can NOT select a category (right now there is only one called “testcategory”). And if I add a new one (newcategory), the field for inserting it becomes blank after hitting enter and NO category got assigned. If I now check the list of all events, another empty event “(no title) – Draft” has been created. Really really weired.I really hope something of what I wrote you gives a hint about what I am doing wrong. Should be possible to create a damn CPT within one workweek shouldnt it? ??
Regards
ThomasI just came a step further.
I renamed my taxonomie “events” to “events_kategorie” (events_categorie in english) and tripple checked all other settings to be exactly like the working one. Now, I can create tags/categories from within an event.
The “Custom slug” field is mandatory for this approach though, because I do not want to have an url like https://omkb.de/events/events_categorie/categoryname.
The only thing still NOT working right now: If I click on the category (which shows in the breadcrumb meanwhile), I get an 404 error. And if I apply my template to “Events Kategorien” in Elementor, that unfortunately does not change anything.
Do you have a tipp here?
Okay, I do not why and I do not how I became Events working now, but it does. Gonna try the same with Company now.
https://omkb.de/events/
https://omkb.de/events/agency-day/
https://omkb.de/events/category/testkategorie/
- The topic ‘CPT UI Category URL’ is closed to new replies.