When I'm creating a new post, just after clicking "Add New", when the post editor shows, instead of having to use the dropdown and choose a custom field to use, I'd like to have some default custom field inputs already openend.
Visually, instead of :
I'd like to have something like :
I know there are plugins for that (CPT, More fields, etc.) but I'd like a simple way to do it with a basic function.
I tried something like this (I'm using a custom post type 'product' ) :
function register_custom_fields( $post_ID ) {
global $wpdb;
if( !wp_is_post_revision( $post_ID ) ) {
add_post_meta( $post_ID, 'reference', '', true);
add_post_meta( $post_ID, 'price', '', true);
}
}
add_action('edit_product', 'register_custom_fields');
But that doesn't seem to work. I think that the hook is probably wrong (because edit_post
comes after an update), but I don't see any hook for "new post" (right after user clicks on "new post" in wp admin). Is there any ?
Or maybe the whole idea is wrong and there's another way?