Skip Navigation

[Gelöst] Any way for a custom post type and page to share the same slug?

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

Here's what I want to do:

- Have a custom post type called Lawyers (uses the slug: 'lawyers' and posts are shown at mydomain.com/lawyers/post123)

- Have a page at mydomain.com/lawyers that shows the Lawyers posts.

So I'd really like to be able to have no archive for lawyers, and instead have a page I can build using different tools.

Solution:

There isn't such a straightforward way to achieve it within Types plugin, and it is a limitation of WordPress, for example, the the page "lawyers" URL is:
domain.com/lawyers/
you create a lawyer post "2", the URL is:
domain.com/lawyers/2/

Wordpress will take above URL as second pagination of page "lawyers".

I suggest you try this:
1) Remove the page "lawyers"
2) use "lawyers" as slug of post type "lawyers"
use Views wordpress archive to customize the archive page of post type "lawyers":
domain.com/lawyers/

Relevant Documentation:

https://toolset.com/documentation/user-guides/normal-vs-archive-views/

This support ticket is created vor 5 Jahre, 11 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 Antworten, has 3 Stimmen.

Last updated by Nick Pierno vor 5 Jahre, 11 Monate.

Assisted by: Luo Yang.

Author
Artikel
#878486

Hi there,

I'm wondering if there's any possible way to have a page and a custom post type use the same slug.

Here's what I want to do:

- Have a custom post type called Lawyers (uses the slug: 'lawyers' and posts are shown at mydomain.com/lawyers/post123)

- Have a page at mydomain.com/lawyers that shows the Lawyers posts.

I understand that the standard approach to this would probably be to use the lawyers archive, but I'd really like to use a particular function in my theme to output the posts ("Grids" feature in WP Bakery/Impreza). So I'd really like to be able to have no archive for lawyers, and instead have a page I can build using different tools.

I feel like I've made this work in the past, but I can't recall how. Any ideas?

#878899

The issue you describe is related to the Slug of Custom Post Types and a Single Post.
When both share the same slug, an error is thrown in Toolset Types when you save the Post Type.

That, cannot be changed. You can hence not have a Post Type and a Page or Post with the same slug.

Suggested is to either edit the Page or Post Slug or the Post Type Slug to something else.

For example, a Page with that Slug can as well make sense if you call it "lawyers-list", or "lawyers-search".

#890811

Thanks, that all makes sense. I'm wondering if there's maybe another way to approach it...

Is it somehow possible to use a different slug for the custom post type for the lawyers (let's say "our-lawyers"), make the page /lawyers/, and adjust the permalink structure of the for lawyer posts to use /lawyers/ as the parent, and not show the slug at all (like how pages and blog posts don't have their slug in the permalinks).

So there would be a page: domain.com/lawyers/

And each lawyer's page would be located at domain.com/lawyers/lawyer-name

Does that make sense? Any straightforward way to achieve that?

#891235

Hello,

There isn't such a straightforward way to achieve it within Types plugin, and it is a limitation of WordPress, for example, the the page "lawyers" URL is:
domain.com/lawyers/
you create a lawyer post "2", the URL is:
domain.com/lawyers/2/

Wordpress will take above URL as second pagination of page "lawyers".

I suggest you try this:
1) Remove the page "lawyers"
2) use "lawyers" as slug of post type "lawyers"
use Views wordpress archive to customize the archive page of post type "lawyers":
domain.com/lawyers/

See our document:
https://toolset.com/documentation/user-guides/normal-vs-archive-views/

#891244

Thanks Luo.

That is what I ultimately resolved to do in this case. It's the kind of thing I'd love to be able to do on future projects, so that's why I continued to pursue it, but IU understand the limitations imposed by WordPress.

Cheers!

#902258

Hi there,

This thread seems to potentially contradict the advice I got here.

Ana seems to be saying that if this user un-checks "has_archive" they will be able to have a "/services/" page and a "Services" custom post type.

This seems to disagree with what Beda told me here "That, cannot be changed. You can hence not have a Post Type and a Page or Post with the same slug."

Any further clarification on this would be much appreciated. Thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.