Displaying different custom post types under one admin menu

Question

I am creating multiple custom post types that have hierarchies, and a few of them are strongly related like a parent-child.

For example, a house custom post type has bedroom and kitchen custom post types as its children.

What I’m trying to do is to display these three custom post types under one admin ui menu so that it may display like below:

House (<– this shall be a menu item in admin ui)

House A (<– this is a post that belongs to ‘house’ custom post type )

-Bedroom 1 (<– this is a post that belongs to ‘bedroom’ custom post type )

-Bedroom 2

-Kitchen 1 (<– this is a post that belongs to ‘kitchen’ custom post type )

-Kitchen 2

-Kitchen 3

House B

-Bedroom 3

-Bedroom 4

-Kitchen 4

So far I could make these custom post types with hierarchy attribute, but couldn’t display them altogether in one admin ui menu. I can display the child custom post types under the parent custom post type by using 'show_in_menu' => 'edit.php?post_type=house', but that is not what I want.

Anyone has idea about how to display different custom post types with parent-child relationship together in one admin menu?

I know there are plugins for this, but I need to do this programmatically.

ADDED

To make my question more clear, this is what I’m trying to achieve but failing:

$args = array(
    'post_title'    => 'House as a parent post',
    'post_type'     => 'house',
    'post_status'   => 'publish'
);

$pid = wp_insert_post( $args );
do_action( 'wp_insert_post', 'wp_insert_post' );

$args = array(
    'post_title'    => 'Bedroom as a child post',
    'post_type'     => 'bedroom',
    'post_parent'   => $pid,
    'post_status'   => 'publish'
);

wp_insert_post( $args );
do_action( 'wp_insert_post', 'wp_insert_post' );

What I want is to create two posts from different custom post types to make a parent-child relationship and be displayed in the same admin-menu like under ‘Dashboard > House’.

0
, Dongsan 6 years 0 Answers 65 views 0

Leave an answer