Custom taxonomy shared across two custom post types – url rewrites

Question

I’m using CPT-UI to create my custom post types and taxonomies.

I have two post types – aulocations and uklocations these work and show up as:

/au/locations/{location-names}
/uk/locations/{location-names}

Next: these post types share a common taxonomy called ‘events’

I’d like urls to display as:

au/events/{event-name} 
uk/events/{event-name}
  • these pages can in turn show the posts that are both in the postype: aulocations or uklocations depending on the base url and in the ‘taxonomy: {event-name}’

Currently when i hit:

/au/events/{event-name} – it redirects back to /events/{event-name} and ignores the post_type


I’ve tried to achieve this by:

1/ wp rewrites

function custom_rewrite_rules() {

    add_rewrite_rule(
        '^au/event/([^/]+)/([^/]+)/', 
        'index.php?post_type=aulocations&event=$matches[1]',
        'top');

    add_rewrite_rule(
        '^uk/event/([^/]+)/([^/]+)/', 
        'index.php?post_type=uklocations&event=$matches[1]',
        'top');
}

add_action('init', 'custom_rewrite_rules');

2/ or via .htaccess


#RewriteRule ^/?au/event/(.*?)?$ /index.php?post_type=aulocations&taxonomy=event&term=$1 [L]
#RewriteRule ^/?uk/event/(.*?)?$ /index.php?post_type=uklocations&taxonomy=event&term=$1 [L]

No luck so far.

0
, , , Simon 3 months 0 Answers 42 views 0

Leave an answer