Skip to content

Instantly share code, notes, and snippets.

@ibes
Created November 27, 2015 14:02
Show Gist options
  • Save ibes/92d6a586773da285f1eb to your computer and use it in GitHub Desktop.
Save ibes/92d6a586773da285f1eb to your computer and use it in GitHub Desktop.
metabox.php
/**
* Generated by the WordPress Meta Box generator
* at http://jeremyhixon.com/tool/wordpress-meta-box-generator/
*/
function produktslogan_get_meta( $value ) {
global $post;
$field = get_post_meta( $post->ID, $value, true );
if ( ! empty( $field ) ) {
return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
} else {
return false;
}
}
function produktslogan_add_meta_box() {
add_meta_box(
'produktslogan-produktslogan',
__( 'Produktslogan', 'produktslogan' ),
'produktslogan_html',
'Product',
'normal',
'default'
);
}
add_action( 'add_meta_boxes', 'produktslogan_add_meta_box' );
function produktslogan_html( $post) {
wp_nonce_field( '_produktslogan_nonce', 'produktslogan_nonce' ); ?>
<p>
<label for="produktslogan_produktslogan"><?php _e( 'Produktslogan', 'produktslogan' ); ?></label><br>
<input type="text" name="produktslogan_produktslogan" id="produktslogan_produktslogan" value="<?php echo produktslogan_get_meta( 'produktslogan_produktslogan' ); ?>">
</p><?php
}
function produktslogan_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! isset( $_POST['produktslogan_nonce'] ) || ! wp_verify_nonce( $_POST['produktslogan_nonce'], '_produktslogan_nonce' ) ) return;
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
if ( isset( $_POST['produktslogan_produktslogan'] ) )
update_post_meta( $post_id, 'produktslogan_produktslogan', esc_attr( $_POST['produktslogan_produktslogan'] ) );
}
add_action( 'save_post', 'produktslogan_save' );
/*
Usage: produktslogan_get_meta( 'produktslogan_produktslogan' )
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment