Add “Post Options” for new wordpress post olatechproMarch 8, 20231 Views How i can add “Post Options” section under wysiwyg editor? Like this Post Views: 1 Related postsGet rid of this Strict Standards warningWooCommerce: get_current_screen not working with multi languageCan’t login on WordPressForce HTTPS using .htaccess – stuck in redirect loopWordPress: Ajax not working to insert, query and result dataHow Can I pass an image file to wp_handle_upload?
You must use add_meta_box function. Take a look to this tutorials: Using add_meta_box() Tutorial: Creating Custom Write Panels in WordPress Example How To Add Meta Boxes To Edit Area Log in to Reply
Try the following code just to get you started. /* Define the custom box */ // WP 3.0+ add_action( 'add_meta_boxes', 'post_options_metabox' ); // backwards compatible add_action( 'admin_init', 'post_options_metabox', 1 ); /* Do something with the data entered */ add_action( 'save_post', 'save_post_options' ); /** * Adds a box to the main column on the Post edit screen * */ function post_options_metabox() { add_meta_box( 'post_options', __( 'Post Options' ), 'post_options_code', 'post', 'normal', 'high' ); } /** * Prints the box content */ function post_options_code( $post ) { wp_nonce_field( plugin_basename( __FILE__ ), $post->post_type . '_noncename' ); $meta_info = get_post_meta( $post->ID, '_meta_info', true) ? get_post_meta( $post->ID, '_meta_info', true) : 1; ?> <h2><?php _e( 'Meta Information' ); ?></h2> <div class="alignleft"> <input id="meta_default" type="radio" name="_meta_info" value="meta_default"<?php checked( 'meta_default', $meta_info ); ?><?php echo ( $meta_info == 1 )?' checked="checked"' : ''; ?> /> <label for="meta_default" class="selectit"><?php _e( 'Use default post setting' ); ?></label><br /> <input id="show_meta" type="radio" name="_meta_info" value="show_meta"<?php checked( 'show_meta', $meta_info ); ?> /> <label for="show_meta" class="selectit"><?php _e( 'Show meta info' ); ?></label><br /> <input id="hide_meta" type="radio" name="_meta_info" value="hide_meta"<?php checked( 'hide_meta', $meta_info ); ?> /> <label for="hide_meta" class="selectit"><?php _e( 'Hide meta info' ); ?></label><br /> </div> <div class="alignright"> <span class="description"><?php _e( 'Your explanation here' ); ?></span> </div> <div class="clear"></div> <hr /><?php } /** * When the post is saved, saves our custom data */ function save_post_options( $post_id ) { // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( @$_POST[$_POST['post_type'] . '_noncename'], plugin_basename( __FILE__ ) ) ) return; // Check permissions if ( !current_user_can( 'edit_post', $post_id ) ) return; // OK, we're authenticated: we need to find and save the data if( 'post' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_post', $post_id ) ) { return; } else { update_post_meta( $post_id, '_meta_info', $_POST['_meta_info'] ); } } } Log in to Reply
You must use
add_meta_box
function.Take a look to this tutorials:
Try the following code just to get you started.