Skip to content

Instantly share code, notes, and snippets.

@MrJoshFisher
Last active May 4, 2023 13:48
Show Gist options
  • Save MrJoshFisher/bb11a10856faa54e86a83e4d7738f457 to your computer and use it in GitHub Desktop.
Save MrJoshFisher/bb11a10856faa54e86a83e4d7738f457 to your computer and use it in GitHub Desktop.
[WordPress Meta Box] #wordpress
function jobs_metaboxes( ) {
global $wp_meta_boxes;
add_meta_box('job_details', __('Job Details'), 'job_details_func', 'jobs', 'normal', 'high');
}
add_action( 'add_meta_boxes_jobs', 'jobs_metaboxes' );
function job_details_func()
{
global $post;
$custom = get_post_custom($post->ID);
$job_expiry_date = isset($custom["job_expiry_date"][0])?$custom["job_expiry_date"][0]:'';
$job_location = isset($custom["job_location"][0])?$custom["job_location"][0]:'';
?>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="job_expiry_date">Job Expiry Date:</label>
</th>
<td>
<input type="date" class="regular-text" name="job_expiry_date" id="job_expiry_date" value="<?php echo $job_expiry_date; ?>">
</td>
</tr>
<tr>
<th scope="row">
<label for="job_location">Job Location:</label>
</th>
<td>
<input type="text" class="regular-text" name="job_location" id="job_location" value="<?php echo $job_location; ?>">
</td>
</tr>
</tbody>
</table>
<?php
}
function jobs_save_post()
{
if(empty($_POST)) return;
global $post;
update_post_meta($post->ID, "job_expiry_date", $_POST["job_expiry_date"]);
update_post_meta($post->ID, "job_location", $_POST["job_location"]);
}
add_action( 'save_post_jobs', 'jobs_save_post' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment