Skip Navigation

[Resolved] URL structure for custom post types with custom taxonomy

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.11 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 3 voices.

Last updated by triD 5 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1184988

Hello!

I am trying to set a URL format for custom post types that will include custom taxonomy

I have set up a custom post type with a slug: psychologists and created a Countries taxonomy for that post type

When I add a new custom post entry, and select a taxonomy, the URL structure is: domainname.com/psychologists/post-title.

I would like the URL to include the taxonomy, i.e. to show the name of the country: domainname.com/psychologists/[country name]/post-title

How can this be achieved?

#1185043

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

WordPress becomes very user-unfriendly once you want to start manipulating the URLs in the way you describe.

It is possible, but requires custom code, which I cannot provide.

You may find this article a helpful starting point:

hidden link

The first part requires setting custom rewrite rules that includes some placeholder text when the post type is first registered, and the second part uses the post_type_link filter to dynamically replace that placeholder text with your custom taxonomy term.

In terms of how you would do the same using Toolset, what you need to know is that the post type is registered by Types (according to what you enter in Toolset > Post types) and you cannot set the rewrite argument as described in the article.

What you can do, though, is use the WordPress filter register_post_type_args to modify the arguments used to register the custom post type as described in the article, by adding code such as this to your theme's functions.php file (not in Toolset > Settings > Custom Code):

function tssupp_custom_rewrite($args, $post_type) {

	$slug = 'project'; // Edit the slug of the post type

	if ($post_type == $slug) {

		$args['rewrite'] = array('slug' => $slug . '/%customtaxonomy%', 'with_front' => 1);
	}

	return $args;
}
add_filter('register_post_type_args', 'tssupp_custom_rewrite', 10, 2);

You would then be in a position to do something similar to what is described in the second part of the article.

If that is not something you are comfortable with, you would need to hire a developer to do it for you.

#1193552

Im looking to do the same, can you post the link again, it's not public

#1193553

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

#1194114

Thanks. I was able to get things working with that link

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.