Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Show us the code. –  scribu Feb 10 '11 at 16:30

2 Answers 2

up vote 3 down vote accepted

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; ?>" />
share|improve this answer
    
Thank you. That is pretty cool. Didn't realize you could do this. –  Manny Fleurmond Feb 10 '11 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. –  MikeSchinkel Feb 10 '11 at 16:57
    
Nice solution, much less intrusive than the direct database intervention mentioned at wordpress.org/support/topic/…. Thank you! –  EFC Jan 18 '13 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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