2

Hello StackExchange WP_development :)

I am in a bit of a pickle with this one and i certainly hope you can consult me further. Im helping out with a WordPress site that is build as a "singlesite". The thing that is tricking me is the URL rewrite.

I have looked around on the web for a solution but with no luck.

The site structure is as following

-Main page - Page template
 --City 1 - Page template
   ---VIP - Page template
      ----VIP subpage - Page template
 --City 2 - page template
   ---VIP - Page template
      ----VIP subpage - Page template
 --City 3 - page template
   --- EVENTS - Page template
      ----CPT which redirects out of stucture(single event)

Here is a example of the URL structure:

Current URL(page templates): www.example.com/city/region/vip
Current URL(for the CPT): www.example.com/event/region/beer-pong/
Desired URL(for the CPT): www.example.com/city/region/event/beer-pong

And my registered post type is using the following:

'rewrite'            => array( 'slug' => 'byer/event' ),
'hierarchical'       => true,
'has_archive'        => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes'),

Normally in quiete fancy with developing in WordPress, but I can simply not wrap my mind arround this....

Unfortunately the URL format is essential, as there is logic developed for the "layers" of the site/pages.

I hope the given information is enough to enlighten you.

WHAT I WANT: to rewrite this URL : /event/region/beer-pong/ to contain a City : city/region/event/beer-pong

WHAT I HAVE: Currently my events made as a Custom Post Type rather than a Page, this can sadly not be changed because the Client won't allow it.

I need your help to solve this!

1

If the city and region is always city and region strings, you can do something like this.

For your specific case, you could do it like this:

'rewrite'            => array( 'slug' => 'city/region/event' ),
'hierarchical'       => true,
'has_archive'        => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes'),

If the city becomes some city and the region becomes some region in the URL i.e. city becomes London and region becomes South East, you have to use global $wp_rewrite and write the regular expression to change add the slugs.

You can find more documentation on WordPress Codex - https://codex.wordpress.org/Class_Reference/WP_Rewrite.

  • Thanks alot for the reply! I have tried that but without any luck - not sure if i mess up the code. City is ALWAYS static Region is dynamic based of a page ID – Andreas Therkildsen Feb 21 '17 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.