Custom URL rewrite rules for a web app

I'm working on a wordpress install that functions more like a web application than a traditional website, and I'm trying to get my head around the add_rewrite_rule system.

Currently I have three custom post types called Programmes, Surveys, and Candidates. Each programme has multiple surveys, and each survey has multiple candidates. I currently have a URL structure like the following:

Programme Overview: /programmes/programme-1/
Survey Overview:    /programmes/programme-1/?survey=survey-1view=overview
Survey Candidates:  /programmes/programme-1/?survey=survey-1view=candidatespage=1
Candidate Overview: /programmes/programme-1/?survey=survey-1view=candidate-1

This works okay but is obviously a bit messy, especially when I also start adding extra query strings like pagination. I currently just check for the post_id and query strings to load the correct template/content.

Ideally I want to have a URL structure that looks more like this:

Programme Overview: /programme-1/
Survey Overview:    /programme-1/survey-1
Survey Candidates:  /programme-1/survey-1/candidates/?page=1
Candidate Overview: /programme-1/survey-1/candidate-1

Something to note is that one survey can be attached to multiple programmes, and the user is allowed access to it depending on the combination of the two, which is handled by some logic within the templates. Example:

/programme-1/survey-1
/programme-1/survey-2
/programme-2/survey-1 // same survey as /programme-1/survey-1
/programme-2/survey-2 // same survey as /programme-1/survey-2

I'm really not sure where to start with the rewrite rules, I've had a look on the docs and through some of the other posts on here, but I'm still at a loss, so if there is anyone out there who may be able to give me a little guidence I'd really appreciate it!

Topic routing rewrite-rules url-rewriting urls custom-post-types Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.