[resolved] WP Bug with Custom Types (11 posts)

  1. driz
    Posted 6 years ago #

    I have my posts sectioned off by using a custom page and setting the permalinks to /news/%category%/%postname%/ which works great.

    The problem is when using custom post types, they inherit the /news/ part of the permalinks, which is incorrect as I have specified a permalink for the type in the functions file. Anyone else agree? Have a solution? Thanks.

  2. driz
    Posted 6 years ago #

    Any thoughts on this?

  3. That is the way they are supposed to work. If your permalinks are set to /news/%category%/%postname%/ there is no way to remove the /news/ from any url on your site.

  4. driz
    Posted 6 years ago #

    So how do I get /news/%category%/%postname%/ for my news posts and /events/event-name/ for events post type?

  5. Change your permalink structure to: /%category%/%postname%/

    Give all your "news" posts a parent category named "news" then create child categories

    When you create the "events" custom post type set your labels array to include:

    'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
  6. driz
    Posted 6 years ago #

    The whole point of WP 3.0 post types was to get away from having to use categories to section off content like this and use them solely for organizing them like they built for.

    I don't get the /news/ part on my pages, so why on my post types? When I have given it a unique permalink. Defo a crappy way of workings in WP!

    The solution above isn't going to work as I want to have URL's like /news/2010/20/post-name/ or /news/category/system-updates/

  7. Mark / t31os

    Posted 6 years ago #

    Set with_front to false in the rewrite arg (defaults to true/enabled).


    'rewrite' => array( 'slug' => 'your_post_type_slug', 'with_front' => false )

    And the URLs will work as you're expecting..

    Code is tested using your permalink settings and a custom post type, works for me... ;)

    NOTE: You may possibly need to click save on the permalink page after making the necessary code change.

  8. driz
    Posted 6 years ago #

    Phew. Glad someone on the WP dev team had thought of this. Thanks t31os_

  9. Mark / t31os

    Posted 6 years ago #

    You're welcome.. :)

    Very easy to replicate so i was pretty confident there'd be a way to fix it.. if not i'd have logged it as a bug (turns out there was no need though).

  10. Good catch t31os_,

    I thought the with_front defaulted to false. There are a few threads with this same problem and nobody could get it to work. I will try and reference them here.

  11. Mark / t31os

    Posted 6 years ago #

    All i did was read the docs, and i don't mean that in a condescending way.

    You could be right c3mdigital, the functionality might have changed, i don't know for sure, but it's certainly possible the default was previously false.

    Happy to help all the same.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.