0

I'm building a WordPress website that should have the following structure:

  • Project A (project post type)
    • About (regular page)
    • Location (regular page)
    • Partners (regular page)
    • News (regular page)
  • Project B (project post type)
    • About (regular page)
    • Book (regular page)

As you see, each project can have random pages below it. The admin should be able to add any page as he wants.

I found some solutions based on setting the hierarchical attribute from my custom post type to true and making it supports page-attributes. Those don't fit my needs because it'll only make possible to add a project under another project.

There is a way to do what I need?

  • If these are only few projects, what about using the navigational menu UI to create this structure? There you can mix it at will. – birgire Mar 25 '16 at 12:07
  • Unfortunately, there are dozens of projects. However, now you mentioned, I may create a menu just to hold all projects hierarchy (instead of a menu for each project), but not display it in the front-end. Only use it as a guide for the structure. I'll give it a try. – Gustavo Straube Mar 25 '16 at 12:14
  • Another approach might be a custom project taxonomy to store the relationships. – birgire Mar 25 '16 at 12:20
  • What about a piece of custom meta that you could use to set a "project post type" as the parent. – TheGentleman Mar 25 '16 at 12:28
  • On the menu approach, I've just realized that if I have an About page for each project, for example, the slug will become about, about-2, about-3 and so on. Also, it doesn't cover the URL structure. I won't have something like /project-a/about, by simply using the menu as the guide for hierarchy. – Gustavo Straube Mar 25 '16 at 12:30
0

I think you're looking for something like this (from Post parent of different type):

I was thrilled to find out what I could do with WordPress Custom Post Types, but very much underwhelmed that you weren’t able to set the parent of a post to be a post of a different type. That is, say you’ve created a custom post type “Chapter”, you couldn’t set the parent of a “Chapter” post to be a “Part” post. The parent had to be of the same type.

I’ve found a simple workaround which essentially replaces the “restriction” WP puts on the parent type. Besides the meta box on the edit post page, there are actually no restrictions on what post type the parent may be.

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
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.