Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function ad_meta_boxes() {
- add_meta_box( 'meta_fields', __('Fields','starter'), 'ad_cb', 'annons', 'side', 'high' );
- }
- add_action( 'add_meta_boxes', 'ad_meta_boxes');
- function ad_cb( $post ) {
- wp_nonce_field( 'ad_meta_fields', 'ad_nonce' );
- $value = get_post_meta( $post->ID, '_price', true );
- echo '<label for="ad_price">';
- _e( 'Price', 'starter' );
- echo '</label> ';
- echo '<input type="text" id="ad_price" name="ad_price" value="' . esc_attr( $value ) . '" size="25" />';
- }
- function ad_save_meta( $post_id ) {
- if ( ! isset( $_POST['ad_meta_fields'] ) ) {
- return;
- }
- if ( ! wp_verify_nonce( $_POST['ad_meta_fields'], 'ad_nonce' ) ) {
- return;
- }
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return;
- }
- if ( isset( $_POST['post_type'] ) && 'ad' == $_POST['post_type'] ) {
- if ( ! current_user_can( 'edit_ad', $post_id ) ) {
- return;
- }
- } else {
- if ( ! current_user_can( 'edit_ad', $post_id ) ) {
- return;
- }
- }
- if ( ! isset( $_POST['ad_meta_fields'] ) ) {
- return;
- }
- $data = sanitize_text_field( $_POST['price'] );
- update_post_meta( $post_id, 'price', $data );
- }
- add_action( 'save_post', 'ad_save_meta' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement