Hierarchical custom post type – can't specify parent
I have declared a hierarchical custom post type called Track. When I create a new Track there is “Attributes” sidebar with only Order in it to specify, but not a Parent post.
I don’t understand what I’m doing wrong and Parent option doesn’t appear. By the way, I’d like to specify another custom post type (called CD) as Track’s Parent.
Would appreciate any help and tips!
Here is the code: http://wordpress.pastebin.com/Y6aagTVs
I checked your code. code is not complete.
[Blatant self-promotion removed – Your URL is in violation of the WordPress trademark usage policy (see http://wordpressfoundation.org/trademark-policy/ for details) and you are not providing the poster with any significant assistance.]
Have you had a chance to review http://codex.wordpress.org/Custom_Post_Types ?
I think you’re looking for the
parentlabel, which Justin calles “Used as a label for a parent post on the edit posts screen. Only useful for hierarchical post types.”
So like this
'labels' => array( 'name' => __( 'Super Dupers' ), 'singular_name' => __( 'Super Duper' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Super Duper' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Super Duper' ), 'new_item' => __( 'New Super Duper' ), 'view' => __( 'View Super Duper' ), 'view_item' => __( 'View Super Duper' ), 'search_items' => __( 'Search Super Dupers' ), 'not_found' => __( 'No super dupers found' ), 'not_found_in_trash' => __( 'No super dupers found in Trash' ), 'parent' => __( 'Parent Super Duper' ), ),
If you look at the code link in the Track custom post type. I have the following in the labels array:
'parent_item_colon' => __('CD'), 'parent' => __('CD')
WP Codex http://codex.wordpress.org/Function_Reference/register_post_type refers to ‘parent_item_colon’. However, Parent drop down menu still doens’t appear.
I think I’m missing something out, but don’t know what 🙁
Will appreciate any help!
Actually in your example, you have a comma after the call to parent but NOT in the parent itself.
$labels = array( 'name' => _x('CD', 'post type general name'), 'singular_name' => _x('cd', 'post type singular name'), 'add_new' => _x('Add New', 'CD'), 'add_new_item' => __('Add New CD'), 'edit_item' => __('Edit CD'), 'new_item' => __('New CD'), 'view_item' => __('View CD'), 'search_items' => __('Search CDs'), 'not_found' => __('No CDs found'), 'not_found_in_trash' => __('No CDs found in Trash'), 'parent_item_colon' => '' );
There should be a , after
'parent_item_colon' => ''I think.
Mind you, most of my info comes from reading http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
I think it’s definitely ‘parent_item_colon’ instead of just ‘parent’. A comma after the last array element can be omitted.
I found out the following: after I’ve added a track-1 and started to add track-2 suddenly the Parent drop down appeared. So the hierarchical custom post type is similar to WP Pages. When 1 or more posts of custom post type exist then any of them can be a parent of another post of the same (!) custom post type.
What I wanted – is to specify a parent for post of custom post type (ex. Track) to be a post of another custom post type (ex CD). I really don’t know how to do that one….
Ah, that makes sense, actually, since CPTs are posts/pages and not categories (which is the only instance of pre-filled hierarchicals I can think of. Do you really need them to be a full CPT or would categories within the CPT work?
I need them to be full CPT as I have some metadata that is associated with every Track post ( as well as CD post).
It’s a bit of a brainer… don’t know what to do 🙁
Just checking. Do you have a post in CD?
Have you got the solution for this? I am also trying to make one custom post type the parent of another custom post type but the parents that gets populated in the options are the posts of that particular custom post type rather then the posts of the parent custom post type.
Thanks for helping.
While you can technically have one custom post type be a child / parent of another, the admin panel wouldn’t show these relationships.
You would probably have to create a custom admin panel if you require that kind of customisation.
If you look at the URL while managing you Custom Post Type, it probably shows something like:
WordPress admin doesn’t currently support the editing of multiple post types at once
Hi all, I’ve sorted out how to assign a parent (of one custom post type) to a post (of another type). It’s not a fancy solution, but I thought I’d share it here since this post came up in my search for a solution. I’ve explained the fix here:
In fact, the admin does show the parent-child relationship correctly. As for the main site, however, you might have to do a bit more customization.
You might also take a look at the Posts 2 Posts plugin http://wordpress.org/extend/plugins/posts-to-posts/
It allows you to link a post in one post type to one in another. I use it often
So I did what @jszkut suggested.
I didn’t include page attributes when registering my custom post type and then I added my own function:
add_meta_box(‘pageparentdiv’, __(‘Page Attributes’), array( &$this, ‘my_plugin_page_attributes_meta_box’ ), ‘listing’, ‘side’, ‘core’);
and my function is the same as ‘page_attributes_meta_box’ in meta-boxes.php, except I removed ‘post_type’ => $post->post_type from the wp_dropdown_pages. And it works.
It sucks but it works. Now I can use a shortcode and create a landing page of choice.
Hi, great stuff, but…
can somebody explain this to me, how to implement that @jszkut code… 🙁
I’m lost! I’m trying to put that in functions.php …
- The topic ‘Hierarchical custom post type – can't specify parent’ is closed to new replies.