| <ask> saya mau bertanya tentang wordpress saya telah membuat metabox, cara memanggilnya di templet bagaimana ya
ini kode metaboxnya
/** * Adds a meta box to the post editing screen */ function prfx_custom_meta() { add_meta_box( 'prfx_meta', __( 'Meta Box Title', 'prfx-textdomain' ), 'prfx_meta_callback', 'post' ); } add_action( 'add_meta_boxes', 'prfx_custom_meta' );
function prfx_meta_callback( $post ) { wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stored_meta = get_post_meta( $post->ID ); ?> <p> <label for="meta-text" class="prfx-row-title"><?php _e( 'Url gambar', 'prfx-textdomain' )?></label> <input type="text" name="meta-text" id="meta-text" value="<?php if ( isset ( $prfx_stored_meta['meta-text'] ) ) echo $prfx_stored_meta['meta-text'][0]; ?>" /> </p> <?php }
/** * Saves the custom meta input */ function prfx_meta_save( $post_id ) { // Checks save status $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false'; // Exits script depending on save status if ( $is_autosave || $is_revision || !$is_valid_nonce ) { return; } // Checks for input and sanitizes/saves if needed if( isset( $_POST[ 'meta-text' ] ) ) { update_post_meta( $post_id, 'meta-text', sanitize_text_field( $_POST[ 'meta-text' ] ) ); } } add_action( 'save_post', 'prfx_meta_save' );
?> |
Tidak ada komentar:
Posting Komentar