I'm working on a plugin that creates a textbox in my publish metabox that seems to work correctly. It displays the previous value from a custom field that can then be revised. But I can not figure out the syntax for the update_post_meta(). The field updates "empty". I've been searching forums for days to no avail. Can someone help me out?
Thanks in advance.
<?php
add_action( 'post_submitbox_misc_actions', 'get_days_to_publish',5 );
function get_days_to_publish()
{
global $post;
if (get_post_type($post) != 'post') return false;
$value = get_post_meta($post->ID, 'days_to_publish', true);
?>
<div class="misc-pub-section">
<label for="curr-cat-txtbox">Number of days until expiration:</label>
<input name='days_to_publish' type="text" value=<?php echo "$value"; ?> >
</div>
<?php
}
add_action( 'save_post', 'save_days_to_publish');
function save_days_to_publish()
{
global $post;
/* check if this is an autosave */
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
/* check if the user can edit this page */
if ( !current_user_can( 'edit_page', $post->ID ) ) return false;
/* check if there's a post id and check if this is a post */
/* make sure this is the same post type as above */
if(empty($post->ID) || $_POST['post_type'] != 'post' ) return false;
update_post_meta($post->ID, 'days_to_publish', $days_to_publish);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire