Add Custom Metabox in WordPress Custom and Default Post Types
/**
* Textbox Meta Box
*/
function textbox_meta()
{
add_meta_box('website', 'Website URL', 'textbox', 'post', 'normal', 'high');
}
add_action('add_meta_boxes', 'textbox_meta');
function textbox($post)
{
wp_nonce_field('website', 'website_nonce');
$value = get_post_meta($post->ID, '_website', true);
echo '<label for="website">';
_e('Add Here Site URL:', 'textbox');
echo '</label> ';
echo '<input type="text" id="website" name="website" value="' . esc_attr($value) . '" size="25" />';
}
function textbox_save_meta_box_data($post_id)
{
if (!isset($_POST['website_nonce']))
{
return;
}
if (!wp_verify_nonce($_POST['website_nonce'], 'website'))
{
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
{
return;
}
if (isset($_POST['post_type']) && 'page' == $_POST['post_type'])
{
if (!current_user_can('edit_page', $post_id))
{
return;
}
}
else
{
if (!current_user_can('edit_post', $post_id))
{
return;
}
}
if (!isset($_POST['website']))
{
return;
}
$my_data = sanitize_text_field($_POST['website']);
update_post_meta($post_id, '_website', $my_data);
}
add_action('save_post', 'textbox_save_meta_box_data');
* Textbox Meta Box
*/
function textbox_meta()
{
add_meta_box('website', 'Website URL', 'textbox', 'post', 'normal', 'high');
}
add_action('add_meta_boxes', 'textbox_meta');
function textbox($post)
{
wp_nonce_field('website', 'website_nonce');
$value = get_post_meta($post->ID, '_website', true);
echo '<label for="website">';
_e('Add Here Site URL:', 'textbox');
echo '</label> ';
echo '<input type="text" id="website" name="website" value="' . esc_attr($value) . '" size="25" />';
}
function textbox_save_meta_box_data($post_id)
{
if (!isset($_POST['website_nonce']))
{
return;
}
if (!wp_verify_nonce($_POST['website_nonce'], 'website'))
{
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
{
return;
}
if (isset($_POST['post_type']) && 'page' == $_POST['post_type'])
{
if (!current_user_can('edit_page', $post_id))
{
return;
}
}
else
{
if (!current_user_can('edit_post', $post_id))
{
return;
}
}
if (!isset($_POST['website']))
{
return;
}
$my_data = sanitize_text_field($_POST['website']);
update_post_meta($post_id, '_website', $my_data);
}
add_action('save_post', 'textbox_save_meta_box_data');
PRAGMATIC HOTEL CASINO, Las Vegas NV - Mapyro
ReplyDeletePRAGMATIC HOTEL CASINO, Las Vegas 청주 출장샵 NV 89109 Free Parking in 군포 출장샵 the 안산 출장안마 garage at 제천 출장마사지 9.9, and available at all the Wynn & Encore properties. Rating: 3.8 광명 출장샵 · 36 reviews · Price range: $$