Support Forum
Support › MB Custom Post Type › Nested Custom Post Types??Resolved
I'm having trouble using a previous created custom post type in the slug of the next custom post type. I know you can make a custom slug for a CPT, but you can't use the dynamic data from another CPT in the slug, like a State abbreviation. Example:
So the custom post types would be:
or maybe I need locations, services, states, counties, cities.
Under Locations the slug would show the State abbreviation, the County, the City (/locations/state/county/city)
Under Services the slug would be /services/service - unless it's related to a location, then it would append the end of the location URL with /service/ so /locations/state/county/city/service.
Very standard URL structure for SEO, I hope this is making sense.
How do I achieve this in MetaBox?
Embedding images here is a pain so here's the CPT URL STRUCTURE
Hello Jordan,
MB Custom Post Types plugin helps you to create the CPT with UI and standard features of WordPress (https://developer.wordpress.org/reference/functions/register_post_type/), it doesn't support an option to have a dynamic slug for CPT and taxonomy.
You need to create some custom code to rewrite the CPT slug dynamically. Here are some examples:
https://stackoverflow.com/questions/51217355/custom-permalink-with-dynamic-rewrite-tags-on-a-wordpress-custom-post-type
https://stackoverflow.com/questions/59482836/create-a-dynamic-rewrite-rule-for-custom-taxonomy
After implementing this solution with the following code, the URLs are still not being rewritten.
<iframe src="https://pastebin.com/embed_iframe/3WbxzWjS" style="border:none;width:100%"></iframe>
The relationships are properly set in MetaBox:
state-to-county
county-to-city
city-to-service
The test service has relationships properly set, as well as the city, state and county.
<script src="https://pastebin.com/embed_js/3WbxzWjS?theme=dark"></script>
Hello,
Supporting the custom code is beyond our scope, please read more about support policy here https://support.metabox.io/topic/support-policy/
If you are not able to complete the task, we offer a customization service, please contact us by submitting this form https://metabox.io/contact/
for more details.
I've submitted the form.
I haven't heard anything from the team after submitting the form.
hey Jordan!
I'm not sure if this will be a helpful suggestion, but I'd suggest picking up Permalink Manager Pro. I've had to use it for a few non-standard URL structures on client projects. I realize that might seem like a lazy answer but perhaps it's the one that gets you moving.
Hey thank you for the recommendation! Another plugin though 😅 I wish they would just include CPT and rewrites in core! Have you had any issues with SEO or security using this plugin?
Tell me about it, and PLEASE INCLUDE BETTER PERMALINK REWRITE SOLUTIONS IN CORE. I DON'T NEED FULL SITE EDITING.
I hear you on "yet another plugin" but it's light weight and honestly it's pretty lightweight ymmv. I haven't seen a huge impact +/- using this plugin. Including meta infos programmatically is pretty easy if it's not supported directly by your SEO plugin/theme or whatever.