WordPress, use slug as variable not as page slug

The problem:
I have a page that shows profiles: ‘www.example.com/profile/1’

‘1’ being the ID of the profile, i retrieve the ID from the url and make a call to an external file to retrieve the profile information.

That all works fine.

But I now want to use the profile name instead of the ID: ‘www.example.com/profile/nameOfProfile’, WordPress now searches for a page called ‘nameOfProfile’ which obviously does not exist.

My question now is: how can I make it so that the the url ‘www.example.com/profile/nameOfProfile’ loads the page ‘www.example.com/profile’ so I can manually retrieve the name from the url and make the call for the profile?

Read more here: WordPress, use slug as variable not as page slug

Leave a Reply

Your email address will not be published. Required fields are marked *