Skip Navigation

[Fermé] Adding Custom Taxonomy to URL and Permalink not working

This support ticket is created Il y a 11 années et 9 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 7 réponses, has 4 voix.

Last updated by Chris Il y a 11 années et 1 mois.

Auteur
Publications
#1565

Jim

I have been playing around with this for a while and trying now to use your plugin to resolve my issues. Basically, I am creating a multilingual listing site and following your website instructions. I have created a category called Properties(translated) and a Post type that's the same. The post type is setup to use the WordPress rewrite,

I also create a custom taxonomy named type that has Apartments and Homes in there, translated using WMPL.org, also using the default rewrite rules.

On the WP permalink settings I have it setup to use /%category%/%type%/%postname%/

The problem is that the %type% never shows up in the URL, it seems that the taxonomies are not added to the wp rewrite, I tried doing this but it didn't work;

add_filter('post_link', 'type_permalink', 10, 3);
add_filter('post_type_link', 'type_permalink', 10, 3);
 
function type_permalink($permalink, $post_id, $leavename) {
	if (strpos($permalink, '%type%') === FALSE) return $permalink;
 
        // Get post
        $post = get_post($post_id);
        if (!$post || 'page' === $post->post_type) return $permalink;
 
        // Get taxonomy terms
        $terms = wp_get_object_terms($post->ID, 'type');	
        if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
        else $taxonomy_slug = 'defacto';
 
	return str_replace('%type%', $taxonomy_slug, $permalink);
	
}

If anyone knows how to get that url structure working for me, that would be great. I will be adding more Taxonomies to the URl, but this is just to test. I am using %category% first, because if I don't then the Pages start to 404

Thanks in advance,

Jim

#1576

Amir
Supporter

I don't think that this issue is related to Types or Views. Looks like it's actually related with how WordPress generates URLs.

Can you tell us how this relates to Types or to Views?

#1606

Jim

Wow, that was an amazingly crappy response. You know most people take questions as challenges, it seems you guys like to just pass the issue to WP. I was hoping (especially since you promote that your plugin is WPML.org compatible) that this would be the place to get help, but I guess I was wrong.

The real issue is that I can only get the URL to work if I add static text into the CUSTOM POST TYPE (isn't that what your plugin does, create TYPES) like this;

<code>
'rewrite' => array(
'slug' => 'i/%listing%/%type%/%action%/%location%',
'with_front' => false
)
</code>

If I do not put the I in the front, then I am not able to browse Pages/Posts, only Custom Posts. The problem with that is that the letter I should be the term Properties, however there is no way to translate this dynamically like is done using the %taxs%

Yes, this is an issue with the way WP rewrites the URLs for Custom Post Types if you are using anything dynamic in the URL... I just hoped that someone had a solution.

I am going to leave this here and hope that one of your plugin purchasers may have the answer as it seems the PAID SUPPORT here is not really that good at all, I bit pushy in the way you decide not to help anyone,

#1613

Amir
Supporter

I'm trying to help, and excuse me for not helping the way you want.

We've spent quite a lot of time (on WPML) trying to get WordPress rewrite rules to play as we intend and this has always been the most challenging part of that plugin.

When you purchase Views, part of the deal is getting support. If you feel that our support is not what you expect, or that the plugins don't perform well, you can get a full refund.

If that helps, I can invite WPML's lead developer to this thread. There's no way he can tell you why this is happening, but he can certainly point you in the right direction, as to which WordPress core functions generate the (very complex) rewrite rules. Then, you would be able to start debugging this.

Without firing up a debugger and going through the WP code, there's no way to tell why it's producing this result, or another, for a given permalink structure.

#1629

I'm not an expert on complex permalink setups but I do know WP 3.3 has had a bit of an overhaul (performance improvements) in how it treats permalinks - so it would be important to know what version you are using and investigating on what has changed in the core. The other thing is that if you have naming conflicts such as similar values for post type and a category, you could be running into a basic naming conflict. I would avoid having identical wordings between a type and a category etc.

#1636

Jim

I have the latest version of WP and the latest versions of WPML, and WP Types/Views. I do know that this is a wordpress issue. I am sorry for how I sounded, I just guess I should create a plugin like yours.

Basically I already did, and spend days cleaning up the code and making everything great. Thinking I knew enough and I didn't, so I sucked it up and paid for these plugins thinking it would be different since there was supposed to be a link to the translation plugins

I just hoped that there would be an answer and there just isn't. The issue with the Type plugin is that it I am not allowed to type in the %tax% into the actual plugin like I am able to do with PHP

Either way, I will not ask for a refund as I will just give this plugin to someone who doesn't know how to create their own plugin as I can see how this would help someone like that, it's just not for me

Thanks Peter, you are right about WP rewriting being the issue, I am sure that's the case. If I do come up with a workable solution (other than adding static text that can't be translated)

By the way Amir, "I'm trying to help, and excuse me for not helping the way you want." I truly don't believe that anyone who is a tech support person (as I am) would ever answer with a one line sentence that reads "it's not our fault, here's your money back".. Just my opinion,

Other than that, I actually think your two plugins work well together, but do need a little work to allow dynamic permalinks based on taxonomies..Given the amount of people asking for it, I think it's the only other place for your plugin to go.

#16945

+1 for Taxonomies to be in permalink. I need this bad! Example.com/Post-Type/Taxonomy/Post-Name

#16948

@jim This is pretty close to perfect for what I'm doing, maybe it will help you out.

To everyone that needs this end result: hidden link

Im going to be very detailed to make sure its really easy with no mistakes.

- - - - - - - - - - - - - - - - - - -
STEP ONE
- - - - - - - - - - - - - - - - - - -

Create/Edit your WP-Types Taxonomy with these settings

My Taxonomy is for locations in USA so I named it "States" (use whatever you want of course)

--- Name and Desc. ---

Plural: States
Singular: State
Slug: state

--- Visibility ---

Make this taxonomy public (will appear in the WordPress Admin menu)

--- Select Post Types ---

Choose the Custom Post Type that you will using with this new taxonomy. If you haven't created a Custom Post Type yet you can come back to this step.

--- Labels ---

Don't change anything here!

--- Advanced ---

- SELECT: "Hierarchical - like post categories, with parent / children relationship and checkboxes to select taxonomy"

- SELECT: Rewrite (very important)

- Leave "Prepend posts with this slug" BLANK!!!!

- SELECT: Allow permalinks to be prepended with front base

- SELECT: Hierarchical URLs

- SELECT: show_ui

- SELECT: show_in_nav_menus (incase you want to add this taxonomy/category to your menus

- SELECT: show_tagcloud

- SELECT: query_var

- Leave the last two boxes BLANK! Not needed.

Scroll to the bottom and SAVE

- - - - - - - - - - - - - - - - - - -
STEP TWO
- - - - - - - - - - - - - - - - - - -

Create/Edit your WP-Types Post-Type with these settings

My Post-Type is for locations so I named it "Location"

--- Name and Desc. ---

Plural: Locations
Singular: Location
Slug: location

--- Visibility ---

SELECT: Make this Type public (will appear in the WordPress Admin menu)

--- Select Taxonomies ---

Choose the Taxonomies that you will using with this new taxonomy. If you haven't created a Custom Post Type yet you can come back to this step.

--- Labels ---

DONT NEED TO TOUCH THESE

--- Display Sections ---

DONT NEED TO TOUCH THESE

--- Advanced ---

- SELECT: Rewrite

- SELECT: Use a custom URL format

Write this: PostType/%taxonomy% (but use your post and tax)
MY EXAMPLE: location/%state%

- SELECT: Allow permalinks to be prepended with front base

DONT WORRY ABOUT THE REST

Scroll to the bottom and SAVE

- - - - - - - - - - - - - - - - - - -
STEP THREE (last step)
- - - - - - - - - - - - - - - - - - -

Below is a tiny code that you paste in to your Functions.php. If this whole 3 step process doesn't work, you may have done this step (step three) incorrectly.

FILE LOCATION: …../wp-admin/themes/your-theme/functions.php

In the code below, replace the word state (there are 6 you need to replace) with your Taxonomy Slug from step one and you're done!!

// custom taxonomy permalinks
add_filter('post_link', 'state_permalink', 10, 3);
add_filter('post_type_link', 'state_permalink', 10, 3);

function state_permalink($permalink, $post_id, $leavename) {
        if (strpos($permalink, '%state%') === FALSE) return $permalink;

        // Get post
        $post = get_post($post_id);
        if (!$post) return $permalink;

        // Get taxonomy terms
        $terms = wp_get_object_terms($post->ID, 'state');
        if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
        else $taxonomy_slug = 'other';

        return str_replace('%state%', $taxonomy_slug, $permalink);
}

Le sujet ‘[Fermé] Adding Custom Taxonomy to URL and Permalink not working’ est fermé à de nouvelles réponses.