Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tp_custom_meta_boxes() {
- add_meta_box('tp_cs_meta', 'TP Meta', 'tp_custom_post_meta', 'post', 'side', 'high');
- }
- add_action( 'add_meta_boxes', 'tp_custom_meta_boxes' );
- function tp_custom_post_meta( $post ) {
- $photo_credit = get_post_meta( $post->ID, '__photo_credit', true );
- $photo_credit = isset($photo_credit) ? $photo_credit : '';
- ?>
- <p>
- <div class="row-content">
- <label for="featured-post">
- <input type="text" name="photo_credit" id="photo_credit" value="<?php echo esc_attr($photo_credit); ?>" class="widefat">
- <?php _e( 'Featured', 'themeplate' )?>
- </label>
- </div>
- </p>
- <?php
- }
- // Save metadata
- function tp_save_post_meta( $post_id, $post ) {
- //use this for the multiple post type
- $edit_capability = get_post_type_object( $post->post_type );
- if( !current_user_can(), 'edit_post', $post_id ) {
- return;
- }
- $is_autosave = wp_is_post_autosave( $post_id );
- $is_revision = wp_is_post_revision( $post_id );
- if ( $is_autosave || $is_revision ) {
- return;
- }
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return;
- }
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
- return;
- }
- $photo_credit = !empty( $_POST['photo_credit'] ) ? sanitize_text_field($_POST['photo_credit']) : '';
- if( array_key_exists('photo_credit', $_POST ) ) {
- update_post_meta( $post_id, '__photo_credit', $photo_credit );
- }
- }
- add_action( 'save_post', 'tp_save_post_meta', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement