Skip Navigation

[Resolved] Adding a non-CPT to the URL structure

This support ticket is created 5 years, 8 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 5 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1234746

I am creating a list of countries under the URL structure jennarobbins.com/journeyreads. My intro page and individual country pages work fine:
Intro page: hidden link
Example country: hidden link

However, when I try to add another WP page in this structure, I get a 404 error:
hidden link
If I choose the "Use the normal WordPress URL logic" for the CPT (country), the above URL works fine.

I anticipate having to add other WP pages in the future. How can I do so?

#1234814

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi John

The built-in WordPress rewrite rules are to help WordPress identify what should be displayed for a given URL.

The standard rewrite rules for CPTs mean that if you have a "country" post type then individual country posts are displayed with a URL structure such as site.com/country/peru. That way WordPress knows that "peru" is the slug of the country post to be displayed, and not something else, such as a taxonomy archive or a similarly named static page.

You have confused things by using the same URL structure for a static page as you use for the custom post type. It doesn't actually matter whether you use the normal logic or a custom slug for your CPT, they cannot be the same. (It "works" in your case with the normal logic because the two are no longer the same, but if you changed the page URL to match the normal CPT structure it would break, although WordPress wouldn't actually let you.)

So the solution is to not use the same structure for static pages as custom posts.

You could write a custom rewrite function that would aim to intercept such conflicts and handle them, but it's an advanced topic and not something I can help with, I'm afraid.

#1235824

So is there a way to add content types to an existing subdirectory? Either with or without their own slug?

#1236009

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'm not sure what you mean by subdirectory.

You can't mix different types of content with the same URL structure, because WordPress is then unable to disambiguate what content is intended to be displayed given a URL.

If you had a page with the URL site.com/travel-tips/ then if you visit a URL such as site.com/travel-tips/medical/ then WordPress expects medical to be a child page of the travel-tips page. You can't have a "travel tips" custom post type that uses travel-tips as its slug (or custom rewrite rule) because WordPress wouldn't know whether site.com/travel-tips/medical/ referred to a child page or a travel-tips custom post called "medical".

As I say, it is possible to override this behaviour with custom code, but it's an advanced topic outside the scope of the support I can give. An experienced WordPress developer should be able to help you (it isn't something specific to Toolset).

#1240178

Let me give you my scenario. I have a section of the site in the directory /journey-reads. Is it not possible to add custom post types to that section?

Let's say a site was about different countries, which then each had custom post types of movies. How would you add a movie post to both /france and /germany? I'm assuming movies would not have to live under the structure site.com/movies/.

#1240304

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

/journey-reads isn't a "directory", it is a page, so any URL such as /journey-reads/something would also be interpreted by WordPress as a page, specifically a child page of the journey-reads page.

When creating post types with Toolset you can specify alternative slugs much the same as if you were manually registering the post type using the register_post_type function (Toolset provides a user-friendly UI for that very function), when you want to alter how WordPress interprets URLs altogether then you need to write custom rewrite rules for this

Here are a few links to articles about creating custom rewrite rules you may find helpful:

hidden link
hidden link
hidden link

How would you add a movie post to both /france and /germany?
In such an example it sounds like you should be organising the movie posts with a country taxonomy, and some movie could be assigned both the 'france' and 'germany' terms so that it appeared under both term archives, e.g. at site.com/country/france/ and site.com/country/germany/. In the settings for the taxonomy you could use a custom slug instead of 'country', e.g. "movies", but not "movie" if that were the slug of the movie post and so was being used to display single movie posts, e.g. site.com/movie/jaws