Parent of a custom post type WordPress page

I am trying to set my own post type staff

as a child of a page about-us

, for example:

Go from

I have currently tried every possible post on Google and on the Stack, but the closet solution I could find adds below to mine functions.php

, which adds a meta box allowing me to set the parent page manually for individual employees.

add_action('admin_menu', function() { remove_meta_box('pageparentdiv', 'chapter', 'normal');});
add_action('add_meta_boxes', function() { add_meta_box('chapter-parent', 'Part', 

'chapter_attributes_meta_box', 'chapter', 'side', 'high');});
  function chapter_attributes_meta_box($post) {
    $post_type_object = get_post_type_object($post->post_type);
    if ( $post_type_object->hierarchical ) {
      $pages = wp_dropdown_pages(array('post_type' => 'part', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
      if ( ! empty($pages) ) {
        echo $pages;
      } // end empty pages check
    } // end hierarchical check.


However, when combined with 'rewrite' => array('slug' => 'about-us'),

this, it seems to call

and without it

does not work correctly!

First, I am wondering if there is a solution to my problem above, and secondly, is there a better way to achieve this and perhaps without having to manually select the parent page for each individual post, and set the whole whole post type as a child of the page ?

I will definitely update if I make any progress on this!

Don't confuse you anymore, but the motive behind trying to do this has to do with navigation, so my menu system automatically adjusts itself. If that wasn't a problem, I would just use rewrite and have my own menu that I would need to update every time a page was moved or added! Which is obviously not ideal when you have multiple CPTs.


source to share

1 answer

It might have something to do with your call to register_post_type (). You may need to rewrite the following code:

'rewrite' => array('slug' => 'about-us', 'with_front' => false )


The "with_front" part is to remove anything you are currently adding to any post. For example, if in your permalinks section you added all staff posts (which seems to be what you are doing, although this is just a guess since I can't see your setup), with_front will ignore it.

With this solution, you don't need the extra meta boxing feature.

Be sure to visit the permalink page after this change to make sure the links are always cleaned and you don't get 401s ...



All Articles