I want to be able to edit the post_parent of a custom post type. Basically in my use case I want to mimic how WordPress uses attachments: have a custom post type that is sort of a subtype to post or any other post type. WordPress uses the post_parent field on the wp_posts table to link attachments to their parent posts so I want to be able to do the same. I've tried to use wp_update_posts but it seems to time out the connection when I try to call it during a post save. Is there a way of editing the post_parent directly?

  • Show us the code.
    – scribu
    Feb 10, 2011 at 16:30

2 Answers 2


Hi @Manny Fleurmond:

You can add the following HTML to a post metabox you'll have an edit field that lets you edit the raw post_parent ID. Maybe with this knowledge you can build what you need?

<input type="text" id="parent_id" name="parent_id" 
       value="<?php echo $post->post_parent; ?>" />
  • Thank you. That is pretty cool. Didn't realize you could do this. Feb 10, 2011 at 16:54
  • @Manny Fleurmond - Sure, glad I could help. It took me a while to figure it out, especially the use of parent_id instead of post_parent. Feb 10, 2011 at 16:57
  • Nice solution, much less intrusive than the direct database intervention mentioned at wordpress.org/support/topic/…. Thank you!
    – EFC
    Jan 18, 2013 at 18:56

If I well understood the question you can set support for page-attributes when you register a CPT like this:

add_action( 'init', 'register_products_post_type' );
function register_products_post_type() {
    $labels = array(
        'name' => 'Products'

    $args = array(
        'labels'        => $labels,
        'public'        => true,
        'rewrite'       => array(
            'with_front'    => false
        'has_archive'   => true,
        'hierarchical'  => true,
        'menu_position' => 5,
        'supports'      => array( ..., 'page-attributes', ... )

    register_post_type( 'products', $args );

A listbox will appear in the manage post page.

Your Answer

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

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