0

I'm developing a fairly complex portfolio WP theme and I can't seem to figure out the logical and most efficient way to setup hierarchy for content. The content needs a deep hierarchy and I need breadcrumbs and menus to work. The custom post type(CPT) is used for "client work" which ideally would be a sub-page of Work >> Clients >> Client (CPT) in the default Pages structure. But I can't define a Parent page for CPT's. I'm rewriting the slug accordingly but this doesn't seem to maintain the parent/child relationship.

Currently, I have things structured like this:

Work > Clients >> Client >>> Client Work(CPT) >>> Single Work Item

My questions are: 1. Is there a better way to structure this? 2. Should I not use CPT's or how can a I add CPT's into more of a hierarchical structure so they relate to their respective parents?

Here is my CPT registration code:

class cpt_client_work {

function cpt_client_work() {
    add_action('init',array($this,'create_post_type'));
}

function create_post_type() {
    $labels = array(
    'name' => 'Client Work',
    'singular_name' => 'Client',
    'add_new' => 'New Client Work',
    'all_items' => 'All Client Work',
    'add_new_item' => 'New Client Work',
    'edit_item' => 'Edit Client Work',
    'new_item' => 'New Client Work',
    'view_item' => 'View Client Work',
    'search_items' => 'Search Client Work',
    'not_found' =>  'No Client Work found',
    'not_found_in_trash' => 'No Client Work found in trash',
    'parent_item_colon' => 'Parent Client:',
    'parent' => 'Client',
    'menu_name' => 'Client Work'
    );
    $args = array(
        'labels' => $labels,
        'description' => "Client Work",
        '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' => 20,
        'menu_icon' => get_bloginfo('template_directory') . '/_/images/admin-icon.png',
        'capability_type' => 'post',
        'hierarchical' => true,
        'rewrite' => array('slug' => 'work/client'),
        'supports' => array('page-attributes','title','editor','thumbnail','excerpt','custom-fields','revisions','author'),
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true
    ); 
    register_post_type('cpt_client_work',$args);
}
 }
1
  • Note that natively WP has very basic concept of relationships between posts (parent/child is pretty much it). I would look at Posts 2 Posts plugin, which is staple solution for posts relationships.
    – Rarst
    Jul 7, 2013 at 23:08

1 Answer 1

1

You are trying to put Works and Clients on the same level and this is a little confusing. I would suggest you to keep the two entity separeted and the make all the relationship you need with the mentioned Posts to posts plugin.

First of all, create a custom type Work with his own slug ():

...
function create_post_type() 
{
    $labels = array( 
        'name' => 'Work',
        ...
    );
    $args = array(
        'labels' => $labels,
        'rewrite' => array('slug' => 'works'),
        ...
    ); 
    register_post_type('work',$args);
}
...

Then create the Clients:

...
function create_post_type() 
{
    $labels = array( 
        'name' => 'Clients',
        ...
    );
    $args = array(
        'labels' => $labels,
        'rewrite' => array('slug' => 'clients'),
        ...
    ); 
    register_post_type('client',$args);
}
...

Now install the Posts to posts plugin and define the relationship between the two entities:

function my_connection_types() {
    p2p_register_connection_type( array(
        'name' => 'works_to_clients',
        'from' => 'work',
        'to' => 'client'
    ) );
}
add_action( 'p2p_init', 'my_connection_types' );

At this point, your data structure is well built and you can move to the next stage (Clients and Works themes, breadcrumb, etc.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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