Here we will see How to Add Hierarchy to Posts, Custom Post type and Woo Commerce.

1. Posts

add_action('registered_post_type', 'cc_make_posts_hierarchical', 10, 2 );

// Runs after each post type is registered
function cc_make_posts_hierarchical($post_type, $pto){

    // Return, if not post type posts
    if ($post_type != 'post') return;

    // access $wp_post_types global variable
    global $wp_post_types;

    // Set post type "post" to be hierarchical
    $wp_post_types['post']->hierarchical = 1;

    // Add page attributes to post back-end
    // This adds the box to set up parent and menu order on edit posts.
    add_post_type_support( 'post', 'page-attributes' );

}

2. Woo Commerce

add_action('registered_post_type', 'cc_woo_make_posts_hierarchical', 10, 2 );

// Runs after each post type is registered
function cc_woo_make_posts_hierarchical($post_type, $pto){

    // Return, if not post type posts
    if ($post_type != 'product') return;

    // access $wp_post_types global variable
    global $wp_post_types;

    // Set post type "product" to be hierarchical
    $wp_post_types['product']->hierarchical = 1;

    // Add page attributes to product back-end
    // This adds the box to set up parent and menu order on edit products.
    add_post_type_support( 'product', 'page-attributes' );

}

3. Custom Post Type

Here we consider “portfolio” as custom post type

add_action('registered_post_type', 'cc_port_make_posts_hierarchical', 10, 2 );

// Runs after each post type is registered
function cc_port_make_posts_hierarchical($post_type, $pto){

    // Return, if not post type portfolio
    if ($post_type != 'portfolio') return;

    // access $wp_post_types global variable
    global $wp_post_types;

    // Set post type "portfolio" to be hierarchical
    $wp_post_types['portfolio']->hierarchical = 1;

    // Add page attributes to portfolio back-end
    // This adds the box to set up parent and menu order on edit portfolio.
    add_post_type_support( 'portfolio', 'page-attributes' );

}
  • Gagne Wrestling Academy

    This post will assist the internet users for building up new website or even a weblog from
    start to end.

  • logmein.site

    Highly energetic post, I loved that bit. Will there be a
    part 2?