Wednesday, August 7, 2013

Adding a custom meta box to a custom post type day 1

Building off of yesterday's progress (http://persteezy.blogspot.com/2013/08/custom-post-types-in-wordpress.html) there was an argument called register_meta_box_cb that was for a callback function that could be used to add a custom meta box using the add_meta_box func: http://codex.wordpress.org/Function_Reference/add_meta_box
add_meta_box(id, title, callback, post type, context, priority, callback args);

  • id - ID of the meta box section
  • title - visible title of the meta box
  • callback - function for generating the meta box html and can only accept two args from the callback args parameter.
  • post type - the post type you want the meta box in (Can I add this to the default post?)
  • context - choose where you want the meta box (normal, advanced or side)
  • priority - choose how important (placementwise) the meta box is
  • callback args - arguments passed on to the callback func
So with just a few additions/mods to the code this is what it looks like now: http://pastebin.com/89rrkuww
Which makes the image post type look like this:

Now reading through tutorials for creating inputs (http://wp.tutsplus.com/series/reusable-custom-meta-boxes/) they seem to follow outdated techniques I saw when first trying to create my options panel.  Skimming through other tutorials (that are a bit newer), I'm seeing the same thing.  What gives?  So the add_settings_section, add_settings_field and register_setting can't be used here?  Well, I'm going to try using them anyways and I'll see how that works out for me (hopefully well).

After trying out the settings api they do in fact work but only with the save changes button which wouldn't work.  I've also coded it the wrong way: http://pastebin.com/h0TZ1b3Z

So starting over again I need to rethink how I'm going to code this.  Before that comes though I've found that the post type isn't even working.  I keep getting the error "You are not allowed to edit this post" so I went to stackexchange for help: http://wordpress.stackexchange.com/questions/109243/cant-publish-custom-post-type-you-are-not-allowed-to-edit-this-post/
And with the community's help I found a fix but I'm unsure why it's working.

I meant to post this last night but forgot so I'm posting it today lol

No comments:

Post a Comment