WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Permalinks
[resolved] Custom taxonomies (13 posts)

  1. Radovan
    Member
    Posted 3 years ago #

    Hi,
    I like this plugin, give me a great opportunities to create well structured site. But one feature me missing.

    do you plan to add custom taxonomies ? Or could you help me a little bit how to edit your plugin ? Thank you much.

    I have post type named Castback which have 3 custom categories like Photos, Videos and Written about us.

  2. John P. Bloch
    Member
    Plugin Author

    Posted 3 years ago #

    Hi Adorei,

    I have looked into doing this before, but it requires a tremendous amount of work which I have not yet had time to commit to. If you want to submit this as a feature request, you can do so on my bug tracker at http://bugs.johnpbloch.com/. You must be registered, though registration is open to anybody (and you can use openId to register too).

  3. Radovan
    Member
    Posted 3 years ago #

    Hello, good news :)

    i really want this feature. So i edit this plugin.

    http://rapidshare.com/files/416341951/custom-post-permalinks.php

    You can use %category% as universal variable.
    example: /event/%category%/%year%/%event%

    Whole modification is about 10 rows changing with PHP comments :)

    %category% takes all taxonomies asigned with custom post type. Maybe better name will be %taxonomy%. It is on you in next realease.

    Sorry I have't instaled no versional software. So please use some compare file application.

  4. John P. Bloch
    Member
    Plugin Author

    Posted 3 years ago #

    I added your ticket to My bug tracker. Thanks for the patch! I'll have to take a look.

  5. Radovan
    Member
    Posted 3 years ago #

    You are welcome.

    i made this changes:

    1. Add class attribute $post_type_taxonomies
    2. in method option_set add one loop load all taxonomies
    3. in method perm_san commented condition to verify is_object_in_taxonomy for category taxonomy
    4. loop in method extra_permalinks

    It's neccessary to add taxonomy.php to template theme and create function "single_term_title" which will appear in WordPress 3.1

  6. John P. Bloch
    Member
    Plugin Author

    Posted 3 years ago #

    This was added in version 1.1, available for download/update now!

  7. McSalty
    Member
    Posted 3 years ago #

    Hi,

    "1.1 - Added support for all taxonomies"

    I can't find an example on how to use this. If the post_type is "restaurant" and the taxonomy "location"...

    /restaurants/%location%/%restaurant% ?
    /restaurants/%taxonomy%/%restaurant% ?
    /restaurants/%category%/%restaurant% ?

    Thanks for the plugin -- this makes custom post types a hell of a lot more useful!

  8. John P. Bloch
    Member
    Plugin Author

    Posted 3 years ago #

    The structure would look something like this:

    /%post_type%/%location%/%restaurant%

    The one caveat is that you have to use the actual registered name of the taxonomy, not its display name.

  9. McSalty
    Member
    Posted 3 years ago #

    Thanks -- the problem was that I was using the display name.

    It doesn't seem to be possible to use custom taxonomies in wordpress's default permalinks (i.e. for regular posts, not custom post types). Is this something that would be easy to code into the plugin?

  10. John P. Bloch
    Member
    Plugin Author

    Posted 3 years ago #

    No problem!

    I haven't looked, but I imagine it would be somewhat difficult to get custom taxonomies to work in the regular posts, since that post type has an elevated status. It uses the rewrite engine in ways that nothing else does, so that would involve so many sanity checks in so many other places that it would be difficult to keep it under control.

    Of course, I could be wrong. It could be as simple as just hooking into a filter at the end of get_permalink() and doing a str_replace() call to replace the taxonomy's rewrite tag with its slug.

  11. McSalty
    Member
    Posted 3 years ago #

    Ah ok. I found a hack here:
    http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks

    Here's the code I'm using:

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

    It's a manual str_replace for my single taxonomy, "location", but in this case it's all I needed to complete my otherwise functional permalink structure.

    It may be more hassle than it's worth to add the functionality to Custom Post Permalinks, but maybe this post will help someone else who needs the same thing. Thanks again for the plugin!

  12. Iroquois Twist
    Member
    Posted 3 years ago #

    Hello,

    This thread is the closest I've come to the obstacle I'm trying to hurdle.

    I love the plugin, very powerful. However, when I activate the plugin, my custom taxonomy template pages (taxonomy-customtaxname.php) stop working.

    I have a feeling there is some relation in the code mentioned above, but am hesitant (and strapped for time) to dig around in the plugin.

    I would love to be able to customize the post type permalinks and use WP3.0's new custom taxonomy templates.

    Any ideas? Thanks in advance.

  13. McSalty
    Member
    Posted 3 years ago #

    anthonyCCL,

    My code had nothing to do with the plugin -- it was a functions.php patch to make custom taxonomies work in normal post permalinks. (Whereas the plugin sets permalinks for custom post types).

    In the latest version of the plugin, custom taxonomies work out of the box with '%taxonomy_name'. Just make sure you're using the official taxonomy name, not the display name or custom slug. Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic