0

I currently have a custom post type that is set up to be hierarchical.

$labels2 = array(
            'name' => __( 'Services' ),
            'singular_name' => __( 'Service' ),
            'all_items' => __( 'All Services' ),
            'view_item' => __( 'View Service' ),
            'add_new_item' => __( 'Add New Service' ),
            'edit_item' => __( 'Edit Service' ),
            'update_item' => __( 'Update Service' ),
            'search_items' => __( 'Search Services' ),
            'not_found' => __( 'Not Found' ),
            'not_found_in_trash' => __( 'Not Found in Trash' ),
        );
$args2 = array(
            'label' => 'Services',
            'description' => 'Directory of Services',
            'labels' => $labels2,
            'public' => true,
            'query_var' => true,
            'has_archive' => true,
            'rewrite' => ['slug' => 'service', 'with_front' => false],
            'query_var' => false,
            'hierarchical' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'show_in_rest' => true,
            'show_in_nav_menus' => true,
            'show_in_admin_bar' => true,
            'menu_position' => 5,
            'can_export' => true,
            'exclude_from_search' => false,
            'publicly_queryable' => true,
            'capability_type' => 'post',
            'supports' => array('title','thumbnail', 'revisions', 'excerpt', 'editor', 'page-attributes')
        );
 register_post_type( 'services', $args2 );

However, when I set a service as a child of another it displays the proper URL in the page editor for that post (http://example.com/service/parent/child/) but when I try to navigate to that page in the front end it doesn't display the page. I get the index.php file which is showing just posts (not my custom post). I have tried resaving the permalinks page to flush the rewrite rules but nothing seems to work.

  • did you flush your permalinks? – rudtek May 2 '18 at 23:12
  • @rudtek I went to the settings->permalinks page and saved which by my understanding should flush the permalinks – jppower175 May 2 '18 at 23:21
  • can you try commenting out your 'label' line and your 'rewrite' line in tyour args2 array (or temporarily delete them for testing) and see if it works. flush after change. – rudtek May 3 '18 at 1:40

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.