WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Well, I created my custom post, but I am wondering why is this if not for a customizable post page? so, I am guessing in some way, I could add new fields on this custom post and publish it as if it were a normal post WITHOUT installing Advance Custom Fields plugin and so on, just one simple done by myself.

DO anybody know any about this??


share|improve this question
Welcome at WPSE. I am sorry but I have some difficulties understanding your question. Could you maybe find someone to help you with your english? What I think I have understood is that you want to add custom fields to a custom post type? – kraftner Jun 6 '14 at 22:43
yes, is exactly that, I was wondering why wordpress let you create a custom type of post... if not to create it with custom fields as well... Could you help me with that? – jpganz18 Jun 6 '14 at 22:48
You can add custom field to custom post types (CPT). See the Codex page on Custom Fields, to start with. – Pat J Jun 7 '14 at 1:26
up vote 1 down vote accepted

I think you're looking for add_meta_box


// Metabox actions
add_action( 'add_meta_boxes', 'metabox_create' ); // create
add_action( 'save_post', 'metabox_save' ); // save

// Create metabox
function metabox_create() {
  add_meta_box( 'metabox_name', 'Metabox Title', 'metabox_content', 'my_custom_post_type', 'normal', 'high' );

// metabox content
function metabox_content() {
  global $post;

  // custom field data
  $custom = get_post_custom( $post->ID );
  $field_name = $custom['field_name'][0];

  // contents
  <label for="field_name">Field name</label>
  <input name="field_name" id="field_name" value="<?php echo esc_attr( $field_name ); ?>" />

// save metabox fields
function metabox_save() {
  global $post;

  // Ignore autosave
  if ( defined( 'DOING_AUTOSAVE' ) && true === DOING_AUTOSAVE ) { return; }

  // Save post meta.
  update_post_meta( $post->ID, 'field_name', $_POST['field_name'] );
share|improve this answer
Thanks, I think is similar, how can I test it? where should I put this code? I got an undefined function error when I just copy on my main plugin file – jpganz18 Jun 6 '14 at 23:10
I revised the code. Originally written from memory, but forgot the add_action calls. What function is it saying is undefined? You also might want to either move these calls into a class or prefix the function names with the name of your post type to avoid conflicts. – Joey Yax Jun 6 '14 at 23:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.