• Resolved slaafws

    (@slaafws)


    Hi everyone,

    I have a website with a Toolset custom post type called Meetings. The public can use the post form to add their meetings, many of which will have the same name like “Tuesday Meeting” or “Sunday Mornings”. They can call their meeting whatever they want, but the point is there will be duplicate names.

    Of course, WordPress doesn’t like this, with its default post title URL structure that no man dare change, so I need to have a custom “Meeting ID” field be the one WordPress uses for the URL, as in website.com/meeting/12345678, not website.com/meeting/tuesday-meeting. The Meeting ID field will be unique. The post title will not.

    I have tried creating a custom field for the meeting name, and just using the post title field for the ID, but the problem is, the Meeting ID is assigned by me, after the meeting is submitted. WordPress hates this too, so it assigns some long random name, and when I go to change it to the ID, it adds a -2 after it, no matter what I do.

    Why is a platform as sophisticated as WordPress not equipped to take into account that not every post name will be unique in a website? Especially a website that accepts public user post submissions? The rest of my site is fine using the post names, except for this custom post type, so I do not want to change the entire permalink structure of my site to some random post ID.

    How can I make my site use the custom field Meeting ID in the URL and NOT the post title?
    Thanks,
    Beth Shaffer

    • This topic was modified 4 years, 6 months ago by Jan Dembowski.
Viewing 2 replies - 1 through 2 (of 2 total)
  • If you read the details of the paremeters for register_post_type here, you’ll see that there is a reason for the slugs being unique, so that the standard queries work for all post types (see under the publicly_queryable parameter).
    But using the rewrite parameter, you can change your post type’s URLs to be what you want.
    The obvious choice for the unique number you are wanting, would be the post ID. Storing it in a custom field doesn’t make sense since posts have to be queried in a standard way for the rest of WordPress to work.

    Why is a platform as sophisticated as WordPress not equipped to take into account that not every post name will be unique in a website?

    That is why WP adds the -2 on the slug. You don’t have to do a thing, and WP will handle all those titles that are the same. You can see this in action in these forums. People use the same titles, but WP just adds the next number on the end and it’s all good.

    Thread Starter slaafws

    (@slaafws)

    I just downloaded the Permalink Manager plugin and used it to make the URL for meetings website.com/meeting/%post_id%, and it seems to be working as I need it to. I wish this was part of WordPress Core.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use Custom Unique ID Field for URL when Post Title is Not Unique’ is closed to new replies.