I Am trying to create a default custom field drop down with pre populated values from the DB to be shown while creating a new Post or editing a existing post.
I am aware about how to add a single custom field and have added few as follows
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id) {
if ( $_GET['post_type'] != 'page' ) {
add_post_meta($post_id, 'email', 'xyz@mail.com', true);
}
}
This is working fine for me and i am able to see custom field with default value but i am not sure how to add a drop down in place of single text field, i tried something like this but seems like its not working.
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id) {
if ( $_GET['post_type'] != 'page' ) {
<select name="voodoo_dropdown" id="voodoo_dropdown">
<option<?php selected( add_post_meta($post->ID, 'voodoo_dropdown', true), 'USA' ); ?>>USA</option>
<option<?php selected( add_post_meta($post->ID, 'voodoo_dropdown', true), 'Canada' ); ?>>Canada</option>
<option<?php selected( add_post_meta($post->ID, 'voodoo_dropdown', true), 'Mexico' ); ?>>Mexico</option>
</select>
}
return ;
}
Due to my lack of knowledge i am not sure where i am doing wrong or what needs to be done to accomplish this task