By Webloper


2013-03-16 10:25:57 8 Comments

I have one CPT page named as books and one CPT post named as chapters, I am trying to achive this permalink structure here

book1->chapter11
book1->chapter12

book2->chapter21
book2->chapter22

and so on.

Here is my code for books cpt

register_post_type( 
        'books',
        $labels
        ,
            'public'                =>  true,
            'exclude_from_search'   =>  false,
            'publicly_queryable'    =>  true,
            'show_ui'               =>  true,
            'show_in_nav_menus'     =>  true,
            'show_in_menu'          =>  true,
            'show_in_admin_bar'     =>  true,
            'menu_position'         =>  100,
            'capability_type'       =>  'page',
            'map_meta_cap'          =>  true,
            'hierarchical'          =>  true,
            'supports'              =>  array(
                    'title',
                    'editor',
                    'author',
                    'thumbnail',
                    'comments',
                    'page-attributes',          
            ),
            'has_archive'           =>  true,
            'rewrite'               =>  array(
                    'slug'          =>  'book',
                    'with_front'    =>  true,
                    'feeds'         =>  true,
                    'pages'         =>  true
            ),
            'query_var'             =>  true,
            'can_export'            =>  true, 
        ) 

    );

and for chapters cpt

register_post_type( 
        'chapters',
$labels
,
            'public'                =>  true,
            'exclude_from_search'   =>  false,
            'publicly_queryable'    =>  true,
            'show_ui'               =>  true,
            'show_in_nav_menus'     =>  true,
            'show_in_menu'          =>  'edit.php?post_type=book',
            'show_in_admin_bar'     =>  true,
            'menu_position'         =>  100,
            'capability_type'       =>  'post',
            'map_meta_cap'          =>  true,
            'hierarchical'          =>  true,
            'supports'              =>  array(
                    'title',
                    'editor',
                    'author',
                    'thumbnail',
                    'comments',
                    'page-attributes',
                    'post-formats'                    
            ),
            'has_archive'           =>  true,
            'rewrite'               =>  array(
                    'slug'          =>  'book/chapter',
                    'with_front'    =>  true,
                    'feeds'         =>  true,
                    'pages'         =>  true
            ),
            'query_var'             =>  true,
            'can_export'            =>  true,           
        ) 

    );

these url's are working fine

localhost/library/book/html
localhost/library/chapter/preface

individually, but when I try this url

localhost/library/book/chapter/preface

currently as per my cpt settings, its gives me 404 error, I tried template redirect and rewrite flush also, but nothing works, now my question are

  1. is it possible Parent as a page and Children as a posts?
  2. if yes what's wrong with this code, am I am missing here?
  3. my main concern is here url rewriting, it should be

    localhost/library/html/preface

where html is the name of the book and preface is the chapter.

I searched lot here but didn't get the solution it might look similar question to you, but really I need help.

thanks.

Did some changes

like changed parent slug to books and child slug to book/chapters and query_var to chapter so working fine for my question 1 and 2 now looking for 3 question url_rewriting.

thanks.

0 comments

Related Questions

Sponsored Content

1 Answered Questions

Parent page for CPT

  • 2013-07-16 08:41:18
  • Don Munter
  • 435 View
  • 2 Score
  • 1 Answer
  • Tags:   custom-post-types

1 Answered Questions

[SOLVED] Can’t delete a custom post in front end with custom role

1 Answered Questions

Parent child relation between Post and Page

  • 2018-12-29 12:56:52
  • Green Comfort Food
  • 54 View
  • 0 Score
  • 1 Answer
  • Tags:   custom-post-types

1 Answered Questions

[SOLVED] Custom Post-Type not in admin menu

3 Answered Questions

[SOLVED] Parent a CPT to a page

1 Answered Questions

1 Answered Questions

[SOLVED] Remove Post Custom Meta Box

Sponsored Content