• hwechsler

    (@hwechsler)


    Hi,

    I’m really excited about the custom post type together with custom taxonomies. Still, having problems having the features play well together. Maybe someone can explain what I’m missing.

    Through my plugin, I’m creating up custom post type “Products”. A product should be in a product-category, so after that a taxonomy is registered.

    Once all this is done and a new product is added, I add a category from the “product’s” edit screen and check to have the product in this new category. This should, afaik, result in a permalink like “mysite/new-productcategory/product”.

    This already works perfect with “normal” posts and changing their categories & that is were I get my logic from.
    But the custom post (=product) remains in a default “product” cat.

    My permalink structure is /%category%/%postname%/ (as anything else kept resulting in 404s after enabling the plugin).

    My plugin’s code is:


    /*custom post type*/
    add_action('init', 'swpm_custom_post_type');
    function swpm_custom_post_type()
    {

    register_post_type('products', array(
    'label' => __('Products'),
    'singular_label' => __('Product'),
    'public' => true,
    'show_ui' => true, // UI in admin panel
    '_builtin' => false, // It's a custom post type, not built in!
    '_edit_link' => 'post.php?post=%d',
    'capability_type' => 'post',
    'hierarchical' => false,
    'supports' => array('title', 'excerpt', 'editor', 'thumbnail')
    ));
    register_taxonomy( 'product-cats', 'products', array(
    'hierarchical' => true,
    'label' => __('Product-Category'),
    'query_var' => true,
    'rewrite' => true)
    );
    };`

    Can someone please explain what could be changed to make the permalink structure work as described above? Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter hwechsler

    (@hwechsler)

    After waiting for a reply, trying out different approaches and further googleing I’d like to state that this is a pretty clear, straightforward problem. Either I’m missing out on sth. or (what I suspect but hope is not the case), WP is missing something very, very essential. Is this rather a bug (and should be filed as such)?

    Custom Post Type + Custom Taxonomy should result in urls like http://www.domain.com/taxonomy/custom-post-type (or ../tag/tax-tag/custom-post). Where “taxonomy/” is not the default name I register the taxonomy with, but anything that’s put in there in the backend. Just as it’s working /w posts in different categories.

    Using register_taxonomy_for_object_type I was at least able to have a category meta-box on a custom type post. I can even change the custom post’s cat. (if register_post_type _builtin is set to “true” -which it shouldn’t).

    The permalink on the edit screen shown below the title is then correct. But going to that permalink gives me a 404. …->?

    It seems as if much more talented developers than me have started tackling this problem after some discussion a while ago.

    I’m still hoping somebody can give me a hint on how to achieve structured, pretty permalinks with custom post types. Thank you.

    i am running into the same issue…can’t find a solution after a few hours of looking around

    In my portfolio plugin for 3.0, I’ve made a custom post type “portfolio” with different taxonomies, e.g. “portfolio-category, portfolio-customer, portfolio-scope”.

    If you register these taxonomies with the default values in the “rewrite”-setting, you will get something like this:

    http://yourdomain.com/portfolio-category/webdesign/
    http://yourdomain.com/portfolio-category/casestudies/

    That wasn’t what i wanted. The taxonomies should be a level below the portfolio custom post type:

    http://yourdomain.com/portfolio/ (Indexpage for Custom Post Type "Portfolio")
    http://yourdomain.com/portfolio/category/ ("portfolio-category" taxonomie)
    http://yourdomain.com/portfolio/category/webdesign/
    http://yourdomain.com/portfolio/customer/ ("portfolio-customer" taxnomie)

    To do this, you will have to change the rewrite-setting in your regsiter_taxonomie call. Instead of rewrite => true, you can use something similar like this one:

    register_taxnomomy('portfolio-category', array('portfolio'), array('rewrite' => array('slug' => 'portfolio/category')));

    To output these taxonomies, you can create a taxonomy.php or a specific taxonomy-<yourtax>.php template.

    There is only one thing, that doesn’t work properly here. If you have a default permalink-structure for your blogposts, for example ‘blog’. Your taxonomies would look like these:

    http://yourdomain.com/blog/portfolio/category/
    http://yourdomain.com/blog/portfolio/category/webdesign/

    To solve this, the wp hackers added the parameter ‘with_front’ to the register_taxonmie call (The same works for register__post_type):

    register_taxnomomy('portfolio-category', array('portfolio'), array('rewrite' => array('slug' => 'portfolio/category'), 'with_front' => false));

    The permalink-structure looks now okay, but the redirect doesn’t work and you get an 404 error. 3.0 is still beta, so i hope this will be fixed soon.

    Please remember. If you have changed something on the rewrite rules, you have to manually update the permalink-structure in your wordpress admin panel. Just hit the button “Save Changes” in “Settings -> Permalink Settings” and it should be working.

    Hope that helped here.

    – Roman

    CodePoet

    (@design_dolphin)

    @rofflox:

    Does this also work for 2.9.2. or only 3.0?

    //

    Running into the same problem. I can link within the theme using custom links. But I have to redirect all the the permalinks in .htaccess. Otherwise I can’t use breadcrumbs. Haven’t been able to find a solution yet.

    Please fix this.

    The rewrite parameter is also available in 2.9.2. So it should also be possible to create your “hierarchical” rewrite rules there.

    Unfortunately, the “with_front” parameter was introduced in 3.0, because of the new custom post type functionality.

    CodePoet

    (@design_dolphin)

    @rofflox

    Thank you for the reply.

    I tried using that, but I still get the category permalink structure.

    So ‘parent category/child category’ instead of ‘custom taxonomy/term’

    Is there some permalink documentation or .htaccess rewrite I’m overlooking?

    For the normal site I can work around it (although it takes some programming), but some plugins also take the permalink path. And changing at a plugin level might technically not be possible.

    Thank you in advance to anyonoe that know how to solve this, or when it will be solved.

    I’ve never used the taxonomy system before 3.0. So i can’t give you an answer, if the the mechanics before 3.0 were different.

    But in my opinion, it should also be working in 2.9.2 with some limitations (param “with_front” for example).

    Can you give me a real-world example of your “parent category/child category” problem with some links? Also post your .htaccess and your register_taxonomy call here, maybe it’s something wrong there.

    In a fresh install (with a permalink-structure of /%postname%/) i get the following rewrites, without any special settings in the register_taxonomy call.

    http://example.com/taxnomomy/term
    e.g. for a taxonomy "customer"
    http://example.com/customer/apple
    http://example.com/customer/google
    CodePoet

    (@design_dolphin)

    Can you give me a real-world example of your “parent category/child category” problem with some links? Also post your .htaccess and your register_taxonomy call here, maybe it’s something wrong there.

    Sure. Real life example, not sure how to show that. Allow me to explain, currently I am writing the paths for the posts in PHP. That is site wide. Not sure how to explain that. I pastebinned the code here including the functions.php and .htaccess. The permalink structure is set to “/%category%/%postname%.html”

    In a fresh install (with a permalink-structure of /%postname%/) i get the following rewrites, without any special settings in the register_taxonomy call.

    If I use “/%postname%/” setting in the permalinks then the “/taxonomy/term” works, but if I then link to “/taxonomy/term/postname” then I get a 404 with that permalink set-up. The way I resolved that before was to give the custom taxonomy and parent category the same slug. So now it works and wrote the code that creates URLs for that.

    Please feel free to let me know if anything at all is unclear.

    I was having a similar problem and Rofflox’s explanation of what the “with_front” option does solved it. I modified the Custom Post Type UI plugin and added support for Rewrite With Front. You can find it here.

    Up until now, the only way I managed to get it working is this.

    Note that you need to used the default “category” taxonomy, as it won’t work otherwise πŸ™

    Does anyone know if this is suppose to still work in the 3.0.1?

    If I just paste rofflox’s code

    register_taxnomomy('portfolio-category', array('portfolio'), array('rewrite' => array('slug' => 'portfolio/category'), 'with_front' => false));

    it crashes the entire site.

    That’s likely because rofflox spells “taxonomy” “taxnomomy”. The rest of it looks like it should work.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Permalink after changing taxonomy of custom post type’ is closed to new replies.