For a project I have a custom post type called Place. This custom post type can have a page as a parent, and that page can have other parent and so on. Place is always at the end of the sequence. At first I created this CPT as non hierarchical, but now I have been asked to reflect the page structure in the URLs (I created a custom metabox to select a page id in the post_parent field).

So I changed my CPT definition to enable the hierarchical setting and the URLs look as expected: https://mywebsite.com/place/place-grandparent/place-parent/place-with-parentss/

Where "place-grandparent" and "place-parent" are page slugs. But my problem is that I follow that URL and it gives me error 404. I'm not sure if it is because the parent is of a different type or something else. But that would be weird considering that the URL looks good.

Here is my CPT definition:

function create_posttype() {
        'labels' => array(
          'name' => __( 'Places' ),
          'singular_name' => __( 'Place' )
        'public' => true,
        'has_archive' => true,
        'rewrite' => array(
          'slug' => 'place'
        'hierarchical' => true,
        'supports' => array(
          // 'page-attributes',
        'menu_icon' => 'dashicons-location-alt',
        'query_var' => true
add_action( 'init', 'create_posttype' );

What can I do to make this structure work? The place needs to have a page as parent, because the pages have widgets that show all the children Places.

Also, can I remove the "place" part at the beggining of the URL and still make it work?

I'm a newbie with Wordpress so any help would be much appreciated.

  • 1
    Possible duplicate of Custom Post Types 404 Issue – Mayeenul Islam May 28 at 5:16
  • 1
    Did you refresh your permalinks by visiting the permalinks page? – rudtek May 28 at 14:43
  • You may also need to unregister_post_typeand re-register it; once you create a CPT, WP saves info about it and so by unregistering you're clearing any of that old memory of being non-hierarchical. – WebElaine May 28 at 15:16
  • I tried refreshing permalinks and unregistering the post and I still have the problem. I made an experiment and enabled page attributes too see if it has something to do with the post type, and yes. When the parent is of the same post type, the URLs work perfectly, but when the parent is of another type it doesn't work (e.g. Place is child of a Page). Any Ideas on how could I solve that? – Bruno Faúndez May 28 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.