Last active
April 1, 2019 00:43
-
-
Save tradesouthwest/45073c3eca8950963c772182d9e8dbb1 to your computer and use it in GitHub Desktop.
wp select options dropdown for meta box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add meta box to editor | |
* | |
* @strings $id, $title, $callback, $screen, $context, $priority, $args | |
* function's action_added in register cpt | |
*/ | |
function vertycal_date_time_meta_box() | |
{ | |
add_meta_box( | |
'vertycal_mark_done_meta', | |
__( 'Mark As', 'vertycal' ), | |
'vertycal_mark_done_meta_box_cb', //callback | |
'vertycal', // post type screen | |
'side', | |
'low' | |
); | |
} | |
/** | |
* Output the HTML for the metabox. | |
*/ | |
function vertycal_mark_done_meta_box_cb($post) | |
{ | |
global $post; | |
//maybe options | |
$opta = __( 'Select Please' ); | |
$optb = __( 'Pending' ); | |
$optc = __( 'On Board' ); | |
$optd = __( 'Fulfilled' ); | |
$vertycal_mark_done = ''; | |
$vertycal_mark_done = get_post_meta( $post->ID, 'vertycal_mark_done_meta', true ); | |
ob_start(); | |
$vtcl_option = array( | |
'vtcl_selects' => $opta, | |
'vtcl_pending' => $optb, | |
'vtcl_progress' => $optc, | |
'vtcl_complete' => $optd | |
); | |
// Output the field | |
printf( '<select id="%1$s" name="%1$s">', 'vertycal_mark_done_meta' ); | |
foreach( $vtcl_option as $key => $value ) | |
{ | |
echo '<option value="' . $key . '"' . selected( $vertycal_mark_done, $key ) . '>' . $value . '</option>'; | |
} | |
print( '</select>' ); | |
wp_nonce_field( 'vertycal_mark_done', 'vertycal_mark_done' ); | |
$output = ob_get_clean(); | |
echo $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment