• Hi WP Forum,
    I need to find a way to make each page, which a user creates, unique. So e.g. user A and user B can create a page called “Main”. I was thinking that each page url is prefixed with the users id:

    mydomain.com/USERA_ID/main
    mydomain.com/USERB_ID/main

    Is this possible?

    • This topic was modified 4 years, 10 months ago by Jan Dembowski.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Umm… yes and no? You can rewrite an URL to get whatever you want so in theory yes. However, page slugs (“main”) cannot be repeated, they must be unique, so no.

    You can rewrite mydomain.com/USERA_ID/main so it fetches a page whose actual slug is “usera-id-main”, which is a unique slug. You cannot have multiple pages with the slug “main” regardless of whose page it is. They can all have the same title “Main”, but the slug used to get the page has to be unique.

    Thread Starter kasper79

    (@kasper79)

    Hi bcworkz,
    thank you for explaining it to me.
    Is it not possible to create a folder for the user, when he/she registers, and then add all pages to this folder, or are pages not registered with folders?

    Do you have any other suggestions?

    Best Kasper

    Moderator bcworkz

    (@bcworkz)

    Pages are not actually stored in folders. They are all in one big common “folder” if you will. (not really a folder, they come from a DB table). The “folders” that are part of a permalink path are principally for SEO, they are not generally used internally to fetch pages. Pages are fetched based on their slug, the rest is supporting information.

    You can manage what pages are fetched by other criteria besides page slug. For example, a page slug could be “hx9os4hsf” for all it matters, e.g. gibberish. What would be crucial is it’s title is “Main” and it is tagged with “main” and “usera-id”. You could request mydomain.com/tagged/USERA-ID/main/ where the last two “folders” are used to qualify the query by corresponding tags assigned to a page. Only page “hx9os4hsf” would match both tag criteria.

    Another possibility is to make use of pages hierarchical nature. Every user could be given a top level page matching their user name. This page itself doesn’t need to be visible on the front end, it’s used for organizational purposes. Every one of these top level pages can have their own child page named “main”. This is allowed because “main” is always referenced through its parent page. The page is then requested just like you want. WP would handle this automatically by virtue of the parent page matching a user.

    This sounds like I’m contradicting myself from previous assertions. The fact there is a parent page matching the user is a crucial difference. It’s not possible to have duplicate page slugs unless each has a unique parent page.

    Thread Starter kasper79

    (@kasper79)

    Wow @bcworkz thats fantastic, so I’ll try to find a way to create a parent page each time a user registers and then for every page they create, they create child pages of their unique parent page. Makes sense. Thanks for the thorough explanation.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Page url with user id’ is closed to new replies.