WordPress.org

Ready to get started?Download WordPress

Forums

Custom post type permalinks (1 post)

  1. kristarella
    Member
    Posted 1 year ago #

    Hi,

    I'm working on a shop site that is being moved to WordPress and we are trying to get the permalink structure as close to the old shop as possible. The shop plugin we are using (MarketPress) requires us to use custom post types and taxonomies, so I have made the slugs of the taxonomies 'costume' and the slug of the post type 'custom/%product_category%'.

    I've enabled the parsing of %product_category% with a filter on post_type_link(), which is working fine.
    At first the products were not showing because it thought that the product page was a taxonomy page, so I added a new rewrite rule to fix that:

    add_filter('rewrite_rules_array', 'product_rewrite_rules');
    function product_rewrite_rules($rules) {
    	global $wp;
    	$request = explode('/',$wp->request);
    	$term = get_term_by('slug',array_pop($request),'product_category');
    	$newRules  = array();
    	if (empty($term))
    		$newRules["costumes/(.+)/(.+)/?$"] = 'index.php?product=$matches[2]';
    	else
    		$newRules["costumes/(.*)/(.+)/?$"] = 'index.php?product_category=$matches[2]';
    
        return array_merge($newRules, $rules);
    }

    That enables viewing of products just fine, and top level product_category pages show fine too, but child taxonomies are not showing.
    It is basically the same issue as http://wordpress.org/support/topic/same-slug-on-custom-post-type-and-hierarchical-taxonomies?replies=2

    If you remove the parent taxonomy term the child taxonomy pages display, but with both term slugs in the URL the page gives a 404, and the query shows that it's trying to use the taxonomy term as a product name instead.
    I.e.
    *http://studio.test/dreampower/costumes/babies/ is a parent taxonomy and works
    *http://studio.test/dreampower/costumes/babies/baby-boys/ is a child tax and doesn't work
    *http://studio.test/dreampower/costumes/baby-boys/ is the same child tax and does work
    *http://studio.test/dreampower/costumes/babies/baby-boys/black-baby-angel-wings/ is a single product and works

    I understand that WordPress does permalinks this way for a reason and if the shop plugin allowed me to use just plain posts and categories that would probably solve all my issues, but we chose this plugin for a bunch of other reasons too...

    Any ideas on why the child tax pages don't work and how to fix that?

    I've tried adding more /(.*) and /(.+) in the regex for the rewrite match too, but it didn't seem to matter how many there were.

Topic Closed

This topic has been closed to new replies.

About this Topic