• Resolved Tokant

    (@tokant)


    Hi,

    I have a page template called Places, which uses this slug: /places/
    It loops through and displays posts from a Custom Post Type with the slug: /caw-places/

    When viewing one of these posts, for example /test-post/, i would like the slug to be: /places/test-post/ instead of /caw-places/test-post/.

    How do i manage this? Through .htaccess rewrite rules?
    Or is there a more logical way within WordPress.

    (Custom Post Types are set up using the Types-plugin)

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    When you register a post type you can define the slug with:

    'rewrite' => array( 'slug' => 'places' ),

    https://codex.www.ads-software.com/Function_Reference/register_post_type

    Custom post types can have archives, the same as you do now with the page ‘/places’ if you register them with this:

    'has_archive' => true,

    This will show all custom post type posts at ‘/places’ (if you used the ‘rewrite’ parameter).

    If you’re using the custom post type archive you’ll need to delete the page ‘/places’ because it will conflict (have the same url) as the post type archive.

    Re-save your permalink structure (wp-admin > Settings > Permalinks) after you change parameters in the register_post_type() function.

    Thread Starter Tokant

    (@tokant)

    Hi,

    Thank You very much for taking your time to answer.

    I am very well aware of the archives-solution. However, it is a more complex to set up pages this way in the menu – through userdefined links – because the menu will then consist of both pages and userdefined links. In addition, i use the WPML translation plugin and this makes it a bit more complex since i need to add userdefined links to each language-menu. Using only pages makes the translated menus more automated.

    That is why i am still interested in knowing if there is a way to only use pages.

    Thanks again!

    Moderator keesiemeijer

    (@keesiemeijer)

    So pages get added automatically to menus. What do you mean by adding “userdefined links”? Are you adding all custom post type posts to a menu?

    I’m not familiar with WPML. Maybe try their support forums:
    https://wpml.org/forums/

    Thread Starter Tokant

    (@tokant)

    No, pages are not added automatically.

    When you set up a custom menu you have different options. Among others; adding pages and userdefined links.

    If one uses Custom Post Type archives, these are added to the menu through userdefined links as they are not set up as a page under Pages.
    So yes, right now by using your method i am adding the Custom Post Type archive page to the menu.

    This method is not as straightforward compared to simply using pages.

    I could of course add a page which uses a page template called page-places.php which loops through the custom post type that has the slug /caw-places/.
    But the permalinks for each post on the template page will not have the slug /places/ but /caw-places/.

    That is why i need a workaround. Do you have any tips for this second method?

    Moderator keesiemeijer

    (@keesiemeijer)

    I don’t know of an easy workaround for this problem you have. Have you tried the WPML forums yet, maybe they have a solotution to your workflow problem.

    It can probably be achieved with the WP_Rewrite class but that isn’t an elegant solution.

    https://codex.www.ads-software.com/Class_Reference/WP_Rewrite

    Thread Starter Tokant

    (@tokant)

    Thanks alot!

    I will try your recommendations.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Page and CPT slugs’ is closed to new replies.