Ask your WordPress questions! Pay money and get answers fast! (more info)

Wordpress Custom Permalink Rewrite - correct setup WordPress

I am trying to setup a custom permalink structure (for 3 custom posts types - services, activities and locations) and it is all working except for this last issue.

If I just have the activity and services rewrite_tag and permastruct - everything works as expected. BUT if I add the location rewrite and permastruct I get "page not found" for the activity and services links (although the location posts all work). i.e. the second last line in the code below breaks the other permalinks.

So the difference is that the location permalink is not at the same "depth" (not sure of terminology) and seems to break the others.

Am I missing something obvious? Am I just not able to set it up like this? I would like to do this with the current setup.

Thanks for your help!

global $wp_rewrite;

$wp_rewrite->add_rewrite_tag('%activity%', '([^/]+)', 'activity=');
$wp_rewrite->add_rewrite_tag('%service%', '([^/]+)', 'service=');

$wp_rewrite->add_permastruct('activity', '/test/activities/%activity%', array( 'walk_dirs' => false));
$wp_rewrite->add_permastruct('service', '/test/services/%service%', array( 'walk_dirs' => false));

$wp_rewrite->add_rewrite_tag('%location%', '([^/]+)', 'location=');
$wp_rewrite->add_permastruct('location', '/test/%location%',array( 'walk_dirs' => false));

$wp_rewrite->flush_rules();

Answers (2)

2016-05-05

Rempty answers:

Change

$wp_rewrite->add_permastruct('location', '/test/%location%',array( 'walk_dirs' => false));

to


$wp_rewrite->add_permastruct('location', '/test/location/%location%',array( 'walk_dirs' => false));



2016-05-08

Bob answers:

did Rempty's solution work?