Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
any suggestion?? –  Ravi Kumar Mar 16 '13 at 13:06
    
You might care to check out the Posts2Posts plugin. –  Johannes Pille Mar 16 '13 at 15:36
1  
I am curious why you are trying to do this with multiple CPTs instead of one hierarchical CPT, which seems the obvious solution to me. –  s_ha_dum Mar 16 '13 at 15:52
    
I'd also go with one CPT and parent-child entries, it seems like fulfilling all your needs for data management and URL handling. –  Mario Peshev Mar 16 '13 at 19:18
    
ok, I guess for this situation one hierarchical CPT is better, I posted this to just get the idea about parent/child relationship on CPT, now my situation is this, I have 4 entities stores, brands, banks and coupons and they all are related to each other for example "pizza discount" coupon is related to some store "best buy" or bank "hdfc" as well as some category "fast food", I tried this way to differentiate every entity, and now stuck or working alternative on this but didn't find a better solution. Hope this clears your questions. Thanks for your comments. –  Ravi Kumar Mar 20 '13 at 20:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.