add custom fields to the post on admin side

I need to add a custom field in admin section (below the title field) which insert the values of that custom field in the db table.

but all this i want to do through coding like

Read More
<input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( htmlspecialchars( $post->post_title ) ); ?>" id="title" autocomplete="off" />

This is for the text box title I need the same one for age, one for country, and one for date of birth below the title field without using any plugin

I’m really very confused

thanx for help

Related posts

Leave a Reply

3 comments

  1. To insert your own custom field after the title field you will have to invoke the hook edit_form_after_title. You may at the following to your plugin or theme:

    add_action('edit_form_after_title', function() {
      global $post;
      print '<input type="text" name="post_title" size="30" tabindex="1" value="'.esc_attr( htmlspecialchars( $post->post_title ) ).'" id="title" autocomplete="off" />';
    });
    

    Note: the default title field will stop working if you add this field (it won’t save anymore).

    All default post attributes don’t necessarily require a form submit handler. Your field will use the default handlers what come with wordpress. However if you want to add custom fields which are not available yet or if you want to alter default behavior of the handlers then you will have to invoke the save_post hook as well.

    I recommend specifying to the post type you want to hook on by appending the name to the hook (e.g. save_post_book). This hook enables you to apply logic to the form data submitted by the user.