Save selected item from dropdown menu in a meta box as a metadata value for a custom post type

$myterms = get_terms($taxonomies, $args); returns an array of term objects. Use $term->term_id as option value … “<option value=”$term->term_id”>”. esc_html( $term_name ) . “</option>” … and store that ID, not the name. Names can change, the IDs will stay the same – unless someone deletes a term and creates a new one with the same name. … Read more

Custom field values get deleted

Check your variables before you work with them. Your save function gets a parameter $post_id. Use it. From my meta box class for a check box: /** * Saves the content to the post meta. * * @return void */ public function save( $post_id ) { $this->is_allowed_save( $post_id ) and update_post_meta( $post_id, $this->vars[‘key’], empty ( … Read more

Minimum Word Count Before A Post Can Be Made Pending Review

Those transition post hooks run after the post is saved. You will have to interrupt the process earlier. I would hook to wp_insert_post_data. function minWord($data){ if (current_user_can(‘contributor’)) { $num = 150; //set this to the minimum number of words if (str_word_count($data[‘post_content’]) < $num) { $data[‘post_status’] = ‘draft’; } } return $data; } add_action(‘wp_insert_post_data’,’minWord’); Seems to … Read more

Updating wp_options with an array on save_post results in duplicated entries

I had something similar going on when I tried to use the wp_editor() function while inside a custom metabox. It was wanting to save multiple times. Take a look at this. // SAVE Metabox for admin response add_action(‘post_updated’, ‘display_jwl_wp_etickets_response_meta_box_save’); function display_jwl_wp_etickets_response_meta_box_save( $post_id ){ if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; if( !isset( $_POST[‘jwl_wp_etickets_editor_box_nonce_check’] ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)