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 have seen similar questions asked, but mine is a little different. I want to register a post type called 'minutes' that doesn't allow you to add a title or a slug, but when you publish (or autosave) it automatically gives the post a title of today's date, and a slug with a canonical representation of the date.

So, title would be "December 7th, 2012" and the slug would be /minutes/12-7-2012.

I don't want the title bar or slug to even be present on the editor page, because I don't want people to think they can fill in their own title. However, I think disabling titles entirely when registering a custom post type means it can't even get an auto-generated one. I don't know for sure, though, so maybe you can help me understand it. Thank you.

share|improve this question
    
All other aspects of the post would be editable though? This is just a way to control the title and slug of a post? –  developdaly Dec 7 '12 at 19:03
add comment

1 Answer

This is completely untested, but the principles are in place. Get today's date and built the title, build the slug and then insert the post as a draft.

This doesn't take care of disabling the title field from being edited. I imagine what you're looking for would be a Javascript solution that just looks for the field and disables it.

Build the title

function wpse_75303_build_title() {
    $output = date( 'M jS, Y' );
    return $output;
}

Build the slug

function wpse_75303_build_slug() {
    $output = date( 'n-j-Y' );
    return $output;
}

Build the post

function wpse_75303_build_date_post() {
    // Create post object
    $my_post = array(
      'post_title'  => wpse_75303_build_title(),
      'post_name'   => wpse_75303_build_slug(),
      'post_status' => 'draft'
    );

    // Insert the post into the database
    wp_insert_post( $my_post );
}

Fire the action

add_action( 'edit_post', 'wpse_75303_build_date_post' );
share|improve this answer
add comment

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.