Skip Navigation

[Resolved] Custom taxonomy permalinks

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Noman 6 years, 6 months ago.

Assisted by: Noman.

Author
Posts
#576749

Please reopen my ticket

https://toolset.com/forums/topic/custom-taxonomy-permalink/

which is now closed. Tried to post a new reply but I get an error. Thank you.

#576786

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Aris,

Thank you for contacting us. We can continue our discussion here. Please let me know what you require further in regards to original details provided earlier.

Thank you

#576802

Thank you. Sorry for not keeping the thread alive (I got all the warnings but I was away).

In response to your last message,
thank you for providing this resource. Indeed this is a step towards the right direction. But I still don't get the desired result.

(Of course in this link you suggested
https://toolset.com/forums/topic/custom-taxonomies-not-showing-on-permalink/#post-16949
the solution applies also in the case where both custom taxonomies and custom post types are used. In my case I do not use custom post types, I stick to WC products).

I guess the only addition is the code part. All other settings are WP Types defaults (if I'm not mistaken).
The code successfully allowed us to use the custom taxonomy slug in WP's permalinks. So in my case I used

/shop/%watch-category%/

as custom base.

However the end result is (for a single product):

<em><u>hidden link</u></em>

To clarify, the hierarchy is 'Watch -> Men'. The respective slugs are 'watch' and 'watch-mens'.

As you can see the custom code shows only the last child (the subcategory) and not the whole hierarchy. It should be something like

<em><u>hidden link</u></em>

I understand this is not in WP Types context but I still would appreciate your help as I am rather new to WP direct coding.

Thanks again

PS: The code I have used is this:

add_filter('post_link', 'watchcategory_permalink', 10, 3);
add_filter('post_type_link', 'watchcategory_permalink', 10, 3);
 
function watchcategory_permalink($permalink, $post_id, $leavename) {
        if (strpos($permalink, '%watch-category%') === FALSE) return $permalink;

        // Get post
        $post = get_post($post_id);
        if (!$post) return $permalink;
 
        // Get taxonomy terms
        $terms = wp_get_object_terms($post->ID, 'watch-category');
        if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
        else $taxonomy_slug = 'other';
 
        return str_replace('%watch-category%', $taxonomy_slug, $permalink);
}
#576893

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for providing more details. Please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and check this further. Please note that we do not debug custom code or custom requirements much as per our support policy (https://toolset.com/toolset-support-policy/) but I would like to take a look and see what I can find.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please also provide links to your Taxonomy, Product, CPT that you would like to use, anything that's needed for this.

Thank you

#576945

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Aris,

I have done more testing on getting the required URL. Since we are using WooCommerce I find out that the solution given here won’t going to help much: https://toolset.com/forums/topic/custom-taxonomies-not-showing-on-permalink/#post-16949

Here is why:
- Above solution will give us url like: hidden link
- Which means it will give us url like: hidden link
(which is we don’t need).

- We need url like this: hidden link
So I managed to achieve this result with an alternate way, I tried various things and codes but only this is what possible as long as its for your current requirements and I think it's good, I have made a short video explaining what I have done here:
hidden link

A related video I found:
hidden link

Thanks

#578662

Dear Noman,
I reviewed your last post thoroughly. I don't follow though. I couldn't pinpoint any action besides the defaults. I am not famous for my observing capabilities...so please let me know what exactly differentiates the actions in your video from the defaults.
In any case I would appreciate if you could keep this thread open as due to personal issues I am not able to review and reply in a timely manner.

In any case I really appreciate your time and effort.
Thanks

#579028

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Aris,

In the video basically I have shown how to get the url as you need:
hidden link

And yes I have used built-in options, the main thing is creating a Custom taxonomy and setting up categories hierarchy. The custom code solutions we found previously are not useful in the end. So that’s all we can do to get the url structure you need.

Other than that if you are not comfortable with the solution I have used to get that url above, rest falls into pure Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thanks

The forum ‘Types Community Support’ is closed to new topics and replies.

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