WP - Custom Admin Inputs


/ Published in: PHP
Save to your folder(s)

Enables you to add a custom panel in the admin post section for a custom field input


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. // Add Custom Inputs
  4. add_action("admin_init", "admin_init");
  5. add_action("save_post", "save_post");
  6.  
  7. function admin_init() {
  8. add_meta_box( "sectionID", "Section Name", "add_fields", "post-type", "side", "low" );
  9. }
  10.  
  11. function add_fields() {
  12. global $post;
  13. $custom = get_post_custom( $post->ID );
  14. $fieldName = $custom["fieldName"][0];
  15. wp_nonce_field("metaNonce", 'metaNonce'); ?>
  16.  
  17. <label>Field Name:</label>
  18. <input type="text" size="31" name="fieldName" value="<?php echo $fieldName; ?>" /> <?php
  19. }
  20.  
  21. function save_post() {
  22. global $post;
  23. if ( wp_verify_nonce( $_POST['metaNonce'], 'metaNonce' ) ) {
  24. update_post_meta( $post->ID, "fieldName", $_POST["fieldName"] );
  25. }
  26. }
  27.  
  28. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.