wordpress - Custom post type saving and permalink problems -



wordpress - Custom post type saving and permalink problems -

i created cpt, have problems:

when publish or upgrade info entered in field 'ora' saved disappear field. the permalink not take name title of post 1 of elements of metabox 'conduce' takes values cpt.

how can prepare ???

this code.

<?php add_action('init', 'palinsesto_manager'); function palinsesto_manager() { $labels = array( 'name' => 'palinsesto', 'singular_name' => 'programma', 'add_new' => 'aggiungi programma', 'add_new_item' => 'nuovo programma', 'edit_item' => 'modifica programma', 'new_item' => 'nuovo programma', 'all_items' => 'palinsesto', 'view_item' => 'visualizza ', 'search_items' => 'cerca ', 'not_found' => 'programma non trovato', 'not_found_in_trash' => 'programma non trovato nel cestino', ); $args = array( 'labels' => $labels, 'public' => true, 'show_ui' => true, 'rewrite' => array('slug' => 'palinsesto'), 'publicly_queryable' => true, 'has_archive' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_icon' => 'dashicons-format-audio', 'menu_position' => 5, 'supports' => array( 'title', 'thumbnail' ), ); register_post_type('palinsesto', $args); } if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); add_image_size( 'cover', 640, 300 ); } //orario add_action('add_meta_boxes','palinsesto_box_add'); function palinsesto_box_add(){ add_meta_box('palinsesto_box','programmazione','program_palinsesto','palinsesto','normal','high'); } function program_palinsesto($post){ $values = get_post_custom( $post->id ); $selected = isset( $values['giorno'] ) ? esc_attr( $values['giorno'][0] ) : ''; $text = isset( $values['ora'] ) ? esc_attr( $values['ora'][0] ) : ''; wp_nonce_field(__file__, 'palinsesto_nonce'); ?> <p> <label for="giorno"><b>giorno</b></label> <select name="giorno" id="giorno"> <option value="lunedi" <?php selected( $selected, 'lunedi' ); ?>>lunedi</option> <option value="martedi" <?php selected( $selected, 'martedi' ); ?>>martedi</option> <option value="mercoledi" <?php selected( $selected, 'mercoledi' ); ?>>mercoledi</option> <option value="giovedi" <?php selected( $selected, 'giovedi' ); ?>>giovedi</option> <option value="venerdi" <?php selected( $selected, 'venerdi' ); ?>>venerdi</option> <option value="sabato" <?php selected( $selected, 'sabato' ); ?>>sabato</option> <option value="domenica" <?php selected( $selected, 'domenica' ); ?>>domenica</option> </select> </p> <p> <label for="ora"> <b>ora (formato hh.mm)</b></label> <input type="text" name="ora" id="ora" value="<?php echo $text; ?>" /> </p> <p> </p> <?php } //fine orario add_action("add_meta_boxes", "palinsesto_box"); function palinsesto_box() { add_meta_box("palinsesto-meta", "conduce", "palinsesto_manager_meta_options", "palinsesto", "side" ); } function palinsesto_manager_meta_options( $post ) { wp_nonce_field( 'palinsesto_manager_meta_options', 'palinsesto_manager_meta_options_nonce' ); echo '<label for="speaker_id">'; _e("speaker", 'speaker_id' ); echo '</label> '; $args = array( 'post_type' => 'speaker'); $loop = new wp_query( $args ); $speaker_id_values = get_post_meta( $post->id, '_speaker_ids', true ); ?> <?php if ( $loop->have_posts() ): ?> <select name="speaker_id[]" id="speaker_id" multiple="multiple" required> <?php while( $loop->have_posts() ): $loop->the_post(); ?> <?php $selected = ( in_array( get_the_id(), $speaker_id_values ) ) ? 'selected="selected"' : ''; ?> <option value="<?php the_id() ?>" <?php echo $selected; ?>><?php the_title(); ?> </option> <?php endwhile; ?> </select> <p>tieni premuto ctrl per selezionare conduttori</p> <?php endif ?> <?php } add_action('save_post', 'save_palinsesto_manager_meta_options'); function save_palinsesto_manager_meta_options($post_id) { // check if our nonce set. if ( ! isset( $_post['palinsesto_manager_meta_options_nonce'] ) ) homecoming $post_id; $nonce = $_post['palinsesto_manager_meta_options_nonce']; // verify nonce valid. if ( ! wp_verify_nonce( $nonce, 'palinsesto_manager_meta_options' ) ) homecoming $post_id; // if autosave, our form has not been submitted, don't want anything. if ( defined( 'doing_autosave' ) && doing_autosave ) homecoming $post_id; // check user's permissions. if ( 'page' == $_post['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) homecoming $post_id; } else { if ( ! current_user_can( 'edit_post', $post_id ) ) homecoming $post_id; } if ( isset( $_post['speaker_id'] ) ) { $sanitized_data = array(); $data = (array) $_post['speaker_id']; foreach ($data $key => $value) { $sanitized_data[ $key ] = (int)strip_tags( stripslashes( $value ) ); } update_post_meta( $post_id, '_speaker_ids', $sanitized_data ); } } //save add_action('save_post','palinsesto_box_save'); function palinsesto_box_save($post_id){ if( defined( 'doing_autosave' ) && doing_autosave ) return; if ($_post && wp_verify_nonce($_post['palinsesto_nonce'], __file__) ) { if( isset( $_post['giorno'] ) ) update_post_meta( $post_id, 'giorno', esc_attr( $_post['giorno'] ) ); if( isset( $_post['ora'] ) ) update_post_meta( $post_id, 'ora', esc_attr( $_post['ora'] ) ); }}

wordpress save custom-post-type permalinks meta-boxes

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -