122 responses to “How to Create A Custom WordPress Meta Box Instead of Using WordPress Custom Fields”

  1. Vengeance Industries

    You need to add add_action('edit_post','my_meta_save'); to the my_meta_init function. That will save changes.

  2. Pete

    That’s EXACTLY what I’m after… thanks so much

  3. PSD to HTML

    This is just awesome! I created a custom post type but I also wanted to have specific information included and I searched and searched and couldn’t find anything that worked. Until your tutorial! Works perfectly! Thank you very much!

    One thing though I took out the wp_enque_style for the meta.css as it wasn’t working and just did a link to the style sheet in the meta.php file. Works like a charm.

    Also to Christopher B – A big thanks to you as well – u ran into some issues I was having i.e. defining the post type and after reading all your comments (lol) i got it to work. Nicely done.

  4. Noel Madali

    Hey Dimas,
    In what way is it possible to import meta data using CSV format?
    I took a look at the SQL backend and saw that it makes an array in the meta field and I am not sure of a plugin that could do something like that.

    I do recall a CSV importer but I dont believe it does meta data..

  5. Matt

    Where are these fields being saved? I don’t see them in the custom post meta, and I don’t see where to specify where it’s saved.

  6. Nicolas

    Hi, I use more and more your great function it’s helpfull.
    However I’ve a problem.
    In a custom template page I try make a custom query to order shop by zip code
    :

    the_meta();
    $zipcodep=$meta['zipcode];
    ?>

    the query don’t work (query_posts(‘post_type=shops)), works.

    I hope you can help me!

  7. Nate

    Thank so much for this, Dimas. I was beating my head against the wall with Sitepoint’s article on this. You’ve made some drastic improvements here, and it’s working great for me!

  8. Dan

    Hi Dimas, i’ve been reading through your info on meta boxes and post types. I’m pretty stuck on a couple of things, any help would be great!

    1) I’ve added to custom post types to a site, they work fine. The problem is the meta boxes I add on the page then show up in all other pages (normal pages, not just the custom post type) once the page has been published. The show up as custom fields. There are now lots of them and I could really do with getting rid of them, can’t i just limit them to the page i want them to show on?

    2) This is related to your meta box stuff. Rather than make a custom post type for my home page, i’d like to make a completely bespoke layout in the admin area. When editing a page with my home.php template i’d like to style 4 boxes, the same as the look on the front-end. This makes it obvious which bit your editing and looks just like the page. I would also need tinyMCE to show up in each one i suppose, so the client could choose links/headings/etc. Ive followed your article on adding meta boxes, I managed to get one to show up on the home.php template but it didn’t look right, and all the other stuff like title, editor, revisions etc were still there. I have a feeling this might be because i need the remove_meta_box function or whatever it is. Any ideas at all how i go about achieving this custom back end?

    Sorry for the long post, but i’m pretty damn stuck :(

    Thanks, Dan

  9. Andy

    Top notch tutorial! Does anyone know how to enable wpautop on the custom meta created in the above example?

  10. Jon

    Thanks for sharing. What is the license on this?

  11. 14ner

    Great tutorial, truly helpful.

    I had two quick questions:
    1. I would like to pull the Metabox title to display next to the data, how would I do that?
    2. One of my fields is an img url, how would I pull this onto the page?

    Thanks in advance,

    14ner

  12. TheWebGuy

    This is a great tutorial, but you missed out the part about custom meta boxes in a plugin menu screen, for example a settings area. I have written a quick article to show also how simple that is!

    http://thewebsolutionprovider.com/wordpress/wordpress-tutorials/custom-wordpress-meta-box-for-your-plugins/

  13. Karl

    You are a fkn legend. This helped me so much, and now i’ve converted it to do options pages etc as well.

  14. Aaron

    Thanks for this post, just found it on Google and it’s answered a few questions. Now on to the actual development!

  15. Chad Von Lind

    I have to second Andy’s question. Does anyone know the approach to adding the wpautop filter to the textarea meta boxes?

  16. manjunath sonju

    when i went through as per the tutorial it is success. But the main problem that occured to me is when i tried to change the custom menta field value it is not working. Do you have any idea i would be grateful to you.

  17. Andrea

    I’m trying to put a input file, but it doest work. Can you help me? Thanks

Leave a Reply