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
<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
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: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.
Custom fields in WordPress admin reside in “Custom Meta Boxes”.
To create a meta box use the add_meta_box() function plugged to the “add_meta_boxes” action hook.
To save the fields create a function plugged to the “save_post” action hook – in this function you can validate the fields and save them as post meta.
Read a more detail explanation at https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/
Why not just use custom field post meta data and save yourself a lot of trouble?