WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Page and CPT slugs (7 posts)

  1. Tokant
    Member
    Posted 1 year ago #

    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)

  2. keesiemeijer
    moderator
    Posted 1 year ago #

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

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

    http://codex.wordpress.org/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.

  3. Tokant
    Member
    Posted 1 year ago #

    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!

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    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:
    http://wpml.org/forums/

  5. Tokant
    Member
    Posted 1 year ago #

    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?

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    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.

    http://codex.wordpress.org/Class_Reference/WP_Rewrite

  7. Tokant
    Member
    Posted 1 year ago #

    Thanks alot!

    I will try your recommendations.

Topic Closed

This topic has been closed to new replies.

About this Topic