Meta Box Script for WordPress is a WordPress plugin that provides an API for you to easily implement multiple meta boxes in editing pages in WordPress. It works with custom post types and supports various field types.
Table Of Content
- Features
- Screenshots
- Download and enjoy
- Get Started
- Documentation & Support
- Extending classes and scripts
License: the Meta Box Script for WordPress is distributed under GNU General Public License.
Meta Box Plugin Features
- Allow to create multiple meta boxes
- Support various field types, including: text, textarea, checkbox, checkbox list, radio box, select, wysiwyg, file, image, date, time, color. Developers can easily add more types by extending the script
- Work with custom post types. Each meta box can be defined for many custom post types.
- Written in OOP, allow developers easily extend the script
Screenshots
Basic fields:

Some advanced fields:

Download and enjoy
Download From GitHub (latest development version)
Download From WordPress (latest stable version)
If you like it, please buy me a beer!
(or send via Paypal to email rilwis@gmail.com in case the donation button doesn’t work)
License: the Meta Box Script for WordPress is distributed under GNU General Public License.
Get Started
To start using the meta box plugin, you need to download and extract it into the plugin folder, then activate the plugin via Plugins menu in WordPress
The downloaded package includes a demo folder, which contains a demo.php file. To run the demo with your theme:
- Copy demo/demo.php file to your theme folder
- Open functions.php file of your theme and add the following code at the top of the file:
include 'demo.php';
Go to Add New Post page and see the result
For more documentation, please see the documentation.
Extending Classes
This section will show extending classes, made by our contributors. You might found a class that fit your requirements.
Advanced Meta Box Class
This class is developed by Manny Fresh. The extending class follows all instructions above and this is a good reference for those who want to extend the class.
According his comment:
- Added a ‘get_meta_{$type}’ system, similar to how you had ‘show_field_{$type}’ functions. This allows you to do a number of things: pre-format metadata before you display it or pull data from other sources other than the custom fields/ postmeta table.
- Taxonomy type. Extended from original version. It uses a custom ‘get_meta_taxonomy’ to pull terms from the taxonomy system. It also uses jQuery to support hierarchical taxonomies.
- Rehauled the image system. Now you don’t need to save the images as metadata: I created a ‘get_meta_images’ function that does a query of all the attached image ids and returns that as the meta.
- Added ‘get_field_name’ and ‘get_field_id’ functions. You could change the way you set the name or id attributes of your fields so you could support more complex meta boxes, like ones that pull data from multiple other posts of different post types.
- Parent type allows you to set the post_parent of a post, creating a hierarchical structure across multiple post types. For example, you would implement it like so:
array( 'name' => 'Series: ', 'desc' =>'Select a series', 'id' => 'veda_content_series', 'type' => 'parent', 'parent_type'=>'veda_series' )The parent_type is the custom post type of the parent you want. It then gives you a select field that lets you pick from a list of all the posts of that type. The one you pick gets stored in the post’s post_parent field in the wp_posts table automatically. Cool part is that WordPress saves it automatically because the field’s name is post_parent. No save function required.
Add ‘menu’ select box
This code is written by Asafche. Actually, it’s not a class. It’s just an additional method for new field type. But it worths a try (if you need it, of course).
Sliders
Pippin Williamson wrote this extended class that help users to create Sliders. Refer to his comment to know how to use it.


270 comments
checked(in_array($r, $meta), true, false)
should do the trick in your code
Well, I couldn’t do it. I certainly missed something important. In your last updated package, you brought meta-box.php in place of the more recent meta-box-3.2.2.class.php . I feel like i’m lost ;)
The meta-box.php is version 3.2.2.
The new usage coded added to my class zip should help
http://www.thatfunkedupgeek.com/class-advanced-meta-box.zip
OK, I got it. So, for newbies like me :
In functions.php =>
include “meta-box/meta-box-usage.php”
In class-advanced-meta-box.php =>
require_once(“meta-box-3.2.2.class.php”) (line 29)
In meta-box-usage.php =>
1. include “class-advanced-meta-box.php” in place of the original extending class code
2. new Advanced_Meta_Box($meta_box) in the foreach after you declared your metaboxes
Great work on this. I’ll be adapting it into another, more extensive project. Best meta box script I’ve come across.
Just a note: never insert the closing ?> php tag in a php-only file. The version 3.2.2 of you class not only contains a ?> tag, but a newline after it. This can create numerous headaches. See http://stackoverflow.com/questions/4410704/php-closing-tag for more on that.
Good point Matt. Thank you :). I’ll change it in the next version.
+1 for Best meta box script I’ve come across, really simple and nice to use, thanks!
And +1 also for the trailing new line issue. Just spent an hour trying to get the image field to work and this turned out to be the cause.
Sorry, this is a new unpleasant feedback : I get a “Uncaught ReferenceError: tb_show is not defined” JS alert when trying to click the “upload new image” button.
There is an unexpected PHP closing tag on this line:
tb_show(”, ‘media-upload.php?post_id={$post->ID}; ?>&type=image&TB_iframe=true’);
… but nothing changed when cleaned.
Errr, not sure where that is coming from. Make sure you have up to date versions of both Rilwis’s and my class in the same folder.
Thank you so much !
I will try this week-end.
It works now ! Thanks a lot. There is no more “Add selected images” button from the thickbox, though :s I will use the file uploader anymway.
Are you including the metabox.js file?
Siblings of the same or different post type?
Okay, update to my class. The last link I gave you was from an old version. This new one should take care of problems. I also added 2 things:
-The ability to add terms. This is done by using the add_new attribute.
-Added usage file. This is something I’ve been sorely lacking in. The usage file shows how to use my custom fields. Everything has been tested. If you have any issues, please ask.
http://www.thatfunkedupgeek.com/class-advanced-meta-box.zip
A few more changes to my class, bringing it to version 1.8:
-Changed how the code saves the data. The form field will now be in an array in $_POST, as opposed to being in $_POST directly. Basically, this allowed me separate the code that saves the data in a separate function, making it recursive friendly. It also allowed me to write less code in a separate class extension I’m working on.
-In addition to how Rilwis did it before, data validation can now be done via filter. I have an example in my usage file but basically, you create a function and then hook it to either the ‘rw_validate_field’ or ‘rw_validate_field_{field_name}’ filter hooks. Its basically how WordPress does it and I think it works a bit better than the implementation currently in Rilwis’s class.
http://www.thatfunkedupgeek.com/class-advanced-meta-box.1.8.zip
I downloaded http://rilwis.googlecode.com/files/meta-box-3.2.2.zip
I put all files in wp-content/mu-plugins/meta-box folder.
Used this code in a file wp-content/mu-plugins:
include_once ‘meta-box/meta-box-3.2.2.class.php’;
include ‘meta-box/meta-box-usage.php’;
for calling it.
“Add more images” button and “Your favorite color” sections are not working. When i click those, browser going to top of page. I checked js file, it seems loaded correctly.
I guess that it conflicts with some plugins. Do you use Firebug or Chrome Inspector Tool? If yes, can you check if any error are shown in the console?
i didnt see any error on Firebug..
can you try same thing too?
btw.. its working normally if i use plugins directory
Hi. Thanks for the script.
The meta boxes appear on my post and page but not on my custom post type called “profile”.
I edited the array to be ‘pages’ => array(‘profile’) but it doesn’t work.
I extracted the files to the theme directory (not in its own folder)… am I doing that right?
It doesn’t matter where you extract the script. You can extract it to theme folder or to a new folder. I guess the problem comes from another thing, but I don’t see anything strange here :(
Amazing tool. Makes developing much easier. Excellent explanation, too. Thanks!
Are titles and descriptions of fields translatable ? I had trouble translating them and I was wondering did I miss something or it’s the code.
Yes, of course. You can translate these strings when you define the meta box! No need to use .PO files.
So if I add this to a theme I can’t use __() and meta-box would be just as defined.
Not really. You have 2 options here:
- Translate directly when you define meta box
- Or using __() to translate.
For ex:
‘desc’ => ‘Your translated string’
or
‘desc’ => __(‘Your English string’, $textdomain)
Rilwis, unfortunately I can’t get it translated like this -
’desc’ => __(‘Your English string’, $textdomain)
Whatever is in array not getting translated by .po file. I had this problem with another meta-box code so I thought it would be different here.
I understand. Are you using POEdit? If so, please update the scan path. By default, it scans the
./folder, you might need to add more path where the meta box script is located.My path is allright. Poedit harvests strings from meta box script then I translate them, but translation is not applied.
If I hack the code
add_meta_box($this->_meta_box['id'],__($this->_meta_box['title'], ‘mythemedomain’), array(&$this, ‘show’), $page, $this->_meta_box['context'], $this->_meta_box['priority']);
it gets translated – but this is wrong
This is so useful, and thanks so much for sharing it.
I’m having a small problem though – I’m using an ‘image’ type meta box, and it’s all working fine, except if I try to delete the image after it’s been set I get a pop-up saying ‘You do NOT have permission to delete this file’. Any thoughts? Am I missing something obvious here? (WP vers. 3.2.1)
Actually something to add to that – despite the popup message detailed above, it does seem to be deleting the image – and if I refresh the WP editing page (without clicking the ‘update’ button) the image thumbnail does then disappear from the metabox.
However, if I just click the ‘Update’ to update the page (without refreshing it first), the image is apparently added to the post again. Hope that makes sense!
Hi,
Please help. It is all working great, just cannot get images uploaded using the image field to show in the theme, even using the first bit of code you gave above. Can you helo please? I get nothing.
update…all I get is the value of the custom field showing in my page. So for example the image uploaded has been assigned the value of 129…on my website I get the number “129″ printed out instead of the image.
Hope you can help.
Thanks
use wp_get_attachment_url function
Hi,
Really appreciate your reply, but nothing happens. I have pasted the following:
…with tvc_project-leader-img as the id of the image.
But nothing happens. What else do I need to do?
Really hope for some help on this. Thanks, Andrew
It didn;t show my code. It was as follows (with the PHP tags wrapped around):
wp_get_attachment_url(tvc_project-leader-img);
@990f900f88c9816216455b67f8bc184b:disqus You’re using the
wp_get_attachment_url()inr wrong way. Please see the Codex to know how to use it.Thanks Rilwis. I’ll give this a go now.
Is there a way also that I can make MP3 files available for download using your amazing script?
Thank you,
Andrew
Hi Rilwis, I still cannot get it to work. Could you please show what i would need to do to get in image from the image field in your script (I have given it the id tvc_project-leader-img) to appear in my page?
Really hoping you can help.
Best wishes,
Andrew
this. is. just. awesome!
This makes life that little bit easier as I’m a bit of a novice.
But I’m having issues when uploading images and “insert selected images” This adds the images fine but when viewing the post no images can be seen. However as soon as I change the order and refresh the post page, images can be seen.
If I try to delete the images form the post I get a notfication “File has been successfully deleted.” but the images can still be seen in the post?!
I’ve pasted my single page code here: http://pastebin.com/QmZf679S
and my functions file here: http://pastebin.com/MwViTA0w
Any help would be most appreciated.
This makes life that little bit easier as I’m a bit of a novice.
But I’m having issues when uploading images and “insert selected images” This adds the images fine but when viewing the post no images can be seen. However as soon as I change the order and refresh the post page, images can be seen.
If I try to delete the images form the post I get a notfication “File has been successfully deleted.” but the images can still be seen in the post?!
I’ve pasted my single page code here: http://pastebin.com/QmZf679S
and my functions file here: http://pastebin.com/MwViTA0w
Any help would be most appreciated.
I have links downloadable mp3′s showing…is it possible to replace the text (which is the title of the uploaded file) with a generic download button?
Thanks again
Adding the script as you’ve described causes a php error of some sort from the `meta-box-usage.php` file. I’m getting a blank page.
I’ve tried it using twentyeleven with the same results… any ideas?
Thanks,
~ Bryan
I’m getting the same result. Have you been able to get it working?
Brett -
I didn’t get it working and am currently using the old version of the script, without the external files.
I’ve used this script on several sites but I’m running into a problem. When I add images to a post and then save and come back and add more, it messes up the order of the images in the post and often deletes them from the thumbnails in the admin, and various other random stuff. Is this a known bug that can be fixed?
Great script, thanks. Is it possible to create a color field with a multiple value? Then we can fetch its value as an array.
I’m having the same issue. Not sure why it’s happening. Nothing in firebug.
Thanks for the script. However, I am getting:
Warning: call_user_func() expects parameter 1 to be a valid
callback, class ‘Advanced_Meta_Box’ does not have a method
‘show_field_slider’ in C:xampphtdocsmetaboxwp-contentthemesquikclass-advanced-meta-box.php on line 273
Sorry, I’m dumb. Forgot to include.
Hi great framework, I could suggest just adding the ability to display some kind of notices for validation, let’s say I have a text field where I can only save the value of “Dolly” as it is now I can write the function fine but it’d be nice to display some kind of message to the user letting them know why the field couldn’t be saved, or is there a way to do it now?
There isn’t a solution for this problem at the moment, sadly. Some people have asked the same question, but it’s really hard.
I see, I tried playing around with the admin_notices hook but I couldn’t get it to work :(
Loving this script so far!
How can I show/hide metaboxes based on a selection in another metabox? For example, I have a hierarchical taxonomy called “Lessons” and under that, terms such as “Private”, “Group”, and “Telephone”.
If I check “Private”, I would like a metabox “Private Lesson Details” to appear which has custom fields like “Rate”, “Session Length”, etc.
I’ve found some methods that seem to do the job:
1. using WPAlchemy MetaBox (with video): http://www.farinspace.com/show-hide-meta-box-by-category/
2. using Jquery: http://wordpress.stackexchange.com/questions/14707/post-formats-how-to-switch-meta-boxes-when-changing-format
How could I do something similar with your script?
Checkboxes weren’t being given id’s. Added id’s and problem solved.
Care to share your code? Did you use the jQuery method?
For some reason whenever I try and include the class.php and usage.php file my entire dashboard disappears. Even when I try and view the source code there’s nothing there.
It appears to be something to do with the usage file as when I delete the include it works again
I’ve used this script a dozen times before and never had this problem.
Any ideas?
Great script, thanks so much for your hard work!
On to my issue… I’ve created a custom meta box (textarea) that I want to function as an addition the_content area. However, when I put text in, with href links, the links don’t turn to clickable links in the template, it just shows the HTML code for it instead.
My meta-box-usage.php code here: http://pastebin.com/UduVJzyC
My template code: http://pastebin.com/5z7F4DhU
Why isn’t the custom meta box parsing the HTML correctly?
@DEAN … check the filename that you are including. I had the exact same problem with my dashboard disappearing. If you’ve downloaded the latest version of the script, the include should look like this:
include_once ‘meta-box-3.2.2.class.php’;
include ‘meta-box-usage.php’;
*Note the filename is meta-box-3.2.2.class.php and NOT meta-box-3.2.class.php
Thanks Ben – I was starting to doubt my WP skills after trying everything and getting the same problem.
Is it possible to display list of published PAGES as a select menu … (just the same way that the “taxonomy” type is used to display categories?
You should initialize the array which contains all categories before defining the meta box. The idea like this:
$cats = get_categories(); $dropdown = array(); foreach ($cats as $cat) { $dropdown[$cat->ID] = $cat->name; } // Define meta box $meta_boxes[] = ... 'fields' => array( array( 'type' => 'select' 'options' => $dropdown ) )I’m still can’t figure it out how to get a select box with all published pages in it. Anyone can help me please?
Hi,i have similar issue then Jen, i want to turn text box value into clickable url on site front end,how can i do that?
tnx
answer my own question,i can add
array(
‘name’ => ‘Visit:’,
‘desc’ => ”,
‘id’ => $prefix . ‘url’,
‘type’ => ‘wysiwyg’,
‘std’ => ‘http://www.',
and make http://www.mysite.com as clickable link with wysiwyg editor,its ugly method,but it works,any better or simple method to do it?
This script is amazing! I found a minor typo in your post above in the code under “Getting Started” – it’s just not updated with the latest version of the meta-box-3.2.2.class.php file. It still has meta-box-3.2.class. No biggie in comparison to how awesome all of your posts are on custom post types and multiple meta boxes with multiple custom post types. Enjoy several beers with the donation, and would love to bump into you sometime if you ever come to any of the WordCamps. (I run WordCamp Chicago – come see us next year!)
Thank you very much for your donation! I wish I could go to WordCamp, but I’m in Vietnam, the distance is too far.
Hey Rilwis,
We have been working on trying to re-instate the WYSIWYG media buttons and visual/HTML tabs.
We have come across a very elegant way of recreating the usual WP text editor components (i.e. tinymce) within custom generated meta boxes – i.e. when you have chosen not to show the Editor (using your script).
All that needs to happen is for the show_field_wysiwyg() function within your meta-box script to be updated with this:
// UPDATES the WYSIWYG field
function show_field_wysiwyg($field, $meta) {
$this->show_field_begin($field, $meta);
the_editor($meta, $field['id']); // calls the WP native function for displaying the editor
$this->show_field_end($field, $meta);
}
We are doing something a bit different with your script (i.e. we don’t use it in the normal way), so it may not work in the usual way but for us it works a treat.
We just thought it may save someone pulling there hair out.
Let me know what you think.
Dave
That’s a good code! I’ll test it for multiple wysiwyg fields, and then will include it into next version :)
Hello Dave,
Thanks for the code. I’ve a got a custom post type without the editor, but lots of wysiwyg fields instead.
I used your code, the usual editor doesn’t display (it’s not specified for the CPT) and all the other wysiwyg fields have the editor displayed – which is great!
However, all of the wysiwyg editors while on the visual tab display HTML code with HTML tags, not the usual visual style. Have you come across that?
Also, a long shot, but do you know by any chance how to have different set of buttons for multiple wysiwyg on the same page?
Many thanks,
Dasha
Actually when trying out the_editor(), my custom code of suppressing some buttons in the editor panels only worked in the first one. So I reverted to using Rilwis’s original code:
echo “$meta”;
Rilwis, do you know what code have to be added in case where wysiwyg fields are added to a Custom Post Type which doesn’t have ‘editor’ supported?
Many thanks,
Dasha
I think I have fixed the problem with wysiwyg fields for CPT which doesn’t have ‘editor’ supported. Can you confirm that with latest version?
Hi Dasha and Rilwis,
I can confirm that Rilwis’s script does not allow multiple WYSIWYG fields to exist with the usual insert media buttons functioning properly either using the script or the code we supplied.
I can also confirm that the image upload option now does not appear to work either.
We are using WP 3.2.1, with Rilwis’s 3.2.2 class.
However, we have been working on an extension class which is currently allowing multiple WYSIWYG fields to exist with working image upload functionality (without the usual meta-box native Editor showing), as well as the Visual/HTML option functionality.
Ideally we are trying to find a solution which gives us the usual WP media upload buttons (within the WP editor toolbar) so that when other plugins (such as NextGEN gallery etc) are used then their toolbar functionality is preserved.
It appears that there will be a complete overhaul to the way in which image uploading occurs in WP as of WP3.3 (using Pluploader) which is due for RC1 in early October, so this may affect things:
http://wpdevel.wordpress.com/2011/07/27/wordpress-3-3-proposed-scope
http://wpdevel.wordpress.com/version-3-3-project-schedule
We are still doing some testing but when we are happy with the performance of our class, then we are very happy to pass it over to Rilwis or anybody else.
In the meantime check our unfinished dev code here:
http://pastebin.com/SffVy8yH
Good luck
HandbuiltDave
@handbuiltDave, Thank you very much for posting your code in the pastebin. I’ve tried the code snippet for the toggle button to switch between the Visual and HTML view.
The switching between editors worked, but unfortunately, it didn’t keep the markup of the content between switching very well ;(
@handbuiltDave, @rilwis guys, maybe you know another way to include HTML tab into the editor?? I even can’t seem to find any good leads to solving it …
I would really appreciate your help!
Many thanks,
Dasha
Actually, I’m waiting for WP 3.3 official. Because the 3.3 version implements the editor in a totally new way with new API. It might be waste of time implementing the switcher between HTML and Visual mode in the editor right now in the meta box script.
@rilwis, I see your point … but at the moment I have several projects that use your meta box script, that I have modified quite a bit and further more, it is not feasible to update the wordpress.
Even though it might seem that implementing switcher between HTML and Visual mode in the editor in the meta box script for WP earlier than 3.3 might seem like a waste of time… I think there are lots of people out there that in the similar situation – who need that functionality and can’t update WP or the script.
I would appreciate any pointers on where to start. I’ve looked around but didn’t go far :(
Thanks,
Dasha
Hi Dasha, I’ve just updated the script to v4.0.1 which supports new WP editor with the switcher and upload buttons. But you have to update WP to v3.3 (beta) to use it.
since those comments are about wysiwyg i have one as well..
so, it works perfect but html tags convert to these symbols: “<p><p><strong>”.. wheres the line for filtering the content?
Awesome script! Getting a lot of use out of it. One bug I’m having trouble with:
The ‘wysiwyg’ type creates a very strange editor box, with a smaller box inside of it and the field title within the editor. As is it’s not very usable. Any ideas?
I’m using WP 3.2.1
Thanks again,
Can you give us a screenshot?
https://picasaweb.google.com/lh/photo/BOm8YJr-CknrXPb13N8-cA?feat=directlink
Thanks.
By the way, I’ve noticed that your example metaboxes (personal information, survey) are appearing in my page editor, and I can’t seem to make them go away. Ideas? I don’t see them in my functions file.
I can’t see the image :(. Is it shared?
The meta boxes appear in page editing page because it’s registered for ‘page’ type. Please see the document for ‘pages’ attributes and you’ll see that.
This should work: https://picasaweb.google.com/lh/photo/BOm8YJr-CknrXPb13N8-cA?feat=directlink
Hi, an small suggestion for show_field_image() with prepare before wpdb query col:
// re-arrange images with 'menu_order', thanks Onurif ( !empty($meta) ) {
$meta = implode(',', $meta);
$images = $wpdb->get_col($wpdb->prepare("
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment'
AND ID in (%s)
ORDER BY menu_order ASC
"), $meta);
I’m writing a few of improvements (IMHO) as other methods (GETTERS, SETTERS)… attributes for globals vars, etc.
Use this (i.e.):
public function _getWPDB() { return $this->_wpdb; // Set on __constructor or in a protected setter. }instead use of globals.
—
Thanks and happy code ;)
Ops…, code standars for public method:
public function getWPDB()Hi rilwis! Nice nice code! I use that for my site :)
My question: Is it possible to display list of site authors as a select menu?
I’ve errors with wp_list_authors
Thanks!
You should use get_users() function to get all blog users. And then loop to that array and create your dropdown box manually.
Thanks rilwis! Work fine now!
and, sorry, for list all custom post type as a dropdown list?
I don’t remember that function. But you can Google for it. Or using PHPXref.
Ok after a simple test i found the solution :)
I think better way is to put that code here for anyone:
$mypostargs = array( ‘post_type’ => ‘name_custom_post_type’, ‘order’=> ‘ASC’ );
$myposts = get_posts( $mypostargs );
$wp_posts = array();
foreach ($myposts as $post) {
$wp_posts[$post->ID] = $post->ID;
}
array_unshift($wp_posts, “Select Post”);
after you just put that code:
array(
‘name’ => ‘myTest1′,
‘id’ => $prefix . ‘mytest’,
‘type’ => ‘select’,
‘options’ => $wp_posts
Thanks for your script rilwis!
Hi, This Class is GREAT and a real life saver!
Being able of uploading multiple images at once is awesome BUT there is somthing I dont understand when trying to upload a single image. I click on “Add more images”, then “Select Files”, I choose the image and “open”. Now…if I hit “Insert selected images” nothing is being inserted, because nothing is selected (cause I uploaded one image) and if I hit “Insert into post” (as in previous versions) the image gets inserted in the very right bottom of the metabox without the “delete” option and disappears when I update or save the post.
So which would be the process for a single image?
Thanks!
Same problem :/
Have a question if is possible, i’ve added that code inside my functions.php file:
_x( ‘Numero di Stelle’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Numero di Stelle’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Cerca numero di Stelle’ ),
‘all_items’ => __( ‘Stelle’ ),
‘parent_item’ => __( ‘Categoria Genitore’ ),
‘parent_item_colon’ => __( ‘Categoria Genitore di:’ ),
‘edit_item’ => __( ‘Modifica’ ),
‘update_item’ => __( ‘Aggiorna’ ),
‘add_new_item’ => __( ‘Aggiungi Nuova’ ),
‘new_item_name’ => __( ‘Nuovo’ ),
‘menu_name’ => __( ‘Stelle’ ),
);
register_taxonomy(‘stelle’,array(‘schedahotel’), array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘query_var’ => true,
‘args’ => array( ‘orderby’ => ‘term_order’ ),
‘rewrite’ => array( ‘slug’ => ‘stars’ ),
));
}
?>
the name for my custom taxonomy is “stelle”. In the usage section, where i can put “stelle”?
array(
‘name’ => ‘Categories’,
‘id’ => $prefix . ‘cats’,
‘type’ => ‘taxonomy’, // taxonomy
‘options’ => array(
‘taxonomy’ => ‘category’, // taxonomy name
‘type’ => ‘select’, // how to show taxonomy? ‘select’ (default) or ‘checkbox_list’
‘args’ => array() // arguments to query taxonomy, see http://goo.gl/795Vm
),
‘desc’ => ‘Choose One Category’
)
Put your taxonomy name in ‘taxonomy’ attribute.
hi. i`m real newbie in wp development. i tried out your script and : on backend it seems fine, but how can i populate my page with, for example, Full Name, wich has rw_fname as meta_key ? i tried this :
but it didn`t work for me. what am i doing wrong? thanks in advance
also i just noticed, when i put: ‘type’ => ‘image’ so it adds upload button “Add more images”, nothing happens, i try to upload, uploader opens, then when i press “insert selected images” nothing on the screen, no message that will notify me of succesfull uploading. i tried to display uploaded image into a page, nothing happens. can you tell me where to look for ? thanks
Can you use these metaboxes on custom admin pages? If yes, how?
This script is designed for posts (and custom post types), not for custom admin pages.
Thanks for your help, great script would be great to use it for all admin page layouts
is there a way to have the ‘Add more images’ functionality on the text field type ?
so to have a button to dynamically add another text field ? i would use this in a scenario where the user fills in dates for an event. but the event can be one day, or two or ten or whatever number. therefore, the need for a ‘Add more’ button.
is this posible ?
Someone has developed this functionality but I couldn’t found where it is :(. It is not possible with default version, but can be possible if we extend the class.
I agree. I have been trying to extend the class with this feature with not much. It would be great if someone can post a solution to be able to have a ‘Add more text’ functionality on a text fields.
Another functionality I have been trying to add is to be able to have multiple text fields for one meta box ID. Any thoughts are greatly appreciated.
I want to use extended class by Pippin Williamson to create slider, but I can’t find Pippin’s comment. How to use this extended class? Thanks
Same question here, where is his comment?
Question… let’s say I have two plugins using this class. How can I get it to work. If I try to activate the second plugin, it shows a fatal error because it’s trying to REDECLARE the class.
Any ideas?
Please open the script and add a wrapper like this:
if ( class_exists( 'RW_Meta_Box' ) ) { // class content here }Is there a way to only show a meta box on a particular page?
For example if I only want to show an image field in the edit screen for page “contact” is that possible?
I’m also looking for the same functionality as Dean Elliott. Anyone could achieve this?
Not sure if you got this answered or not, but you can use jQuery to do this.
Something like this should work:
jQuery(document).ready(function() {
var $ptemplate_select = jQuery(‘select#page_template’); //Creates variable out of the page template select
$(‘#id-of-your-meta-box-pagetype’).hide(); //Hides your meta box
$ptemplate_select.live(‘change’,function(){
var this_value = jQuery(this).val(); //Creates variable out of select chosen value
$(‘#id-of-your-meta-box-pagetype’).show(); //Shows your meta box
});
});
Just make sure where it says pagetype that it matches the page template names, so that when the value of the page select changes, it shows the meta box associated with that page template.
Hopefully that answers your question.
For a deeper look, Orman Clark uses a similar technique on the Gridlock theme on Themeforest and Elegant Themes also use something similar in their themes.
Hopefully this helps! (FYI, haven’t tested the code, but it should at least get you close.)
hey guys thanks for the great class. I’ve been using it on a recent project and have a strange issue. when the meta-box code is included in my site the native WP media popup will not display available images from the media library anywhere on the site. i get the counts but can’t see images or select them. Comment those lines out, and it works properly. any ideas?
thanks
any ideas at all? i’ve exhausted everything i can think of to solve this one.
solved…one of my custom post types had a taxonomy named “type” and that must be a reserved term. changed the name and all is well.
Hi I was just wondering if this was compatible with the WPML plugin?
@johnjoe, we’re using this with WPML without problems.
This worked so f’ing well, thank you soooo much!!! I’m so excited about the opportunities this opens up. For instance, I’ve been using Magic Fields to handle my custom fields and such, and while it worked extremely well, I couldn’t import CSV files directly into it. So, I had to make my own custom post types, taxonomies, custom fields, as opposed to relying on a plugin. Well, with your script and my tweaks, some custom post type and tax tutorials, I got it working. Just now. So happy!!! I’ve been checking out numerous Meta Box tutorials and such, but found this solution to be the best, even though the others were great. Thanks a ton. Donation coming up right quick!
Thank you for your donation! I’m very glad that the script can help you.
You’re very welcome, it was worth every penny.
Do you know if this solution will work in WordPress Multisite mode? Also, since I want to use this code (and the code for custom post types and taxonomies I created) in many of my themes, I want to turn it into a plugin (instead of putting the same code in numerous functions.php files). Do you have any suggestions for making this a reality? Maybe a link?
Thanks again.
Hi and thank you for all this. The link for Advanced Meta Box Class isn’t working…how can I get it?
Thank you
Hi again. I’m working on a metabox that has a checkbox list in it. When I get the values, they are all reverted, meaning that array[0] is the last value and array[i] is the very first value. Do you know how can I fix it?
Thank you
I’m here again. This is my checkbox list:
$meta_boxes[] = array(
‘id’ => ‘table1′,
‘title’ => ‘Sizes’
‘page’ => ‘post’,
‘context’ => ‘normal’,
‘priority’ => ‘high’,
‘fields’ => array(
array(
‘name’ => ‘Size’,
‘id’ => $prefix . ‘sizes’,
‘type’ => ‘checkbox_list’,
‘options’ => array(
’70/80′ => ‘S’,
’80/95′ => ‘M’,
’95/110′ => ‘L’,
’110/125′ => ‘XL’,
’115/135′ => ‘XXL’
))));
I get the infos calling
$metas = get_post_meta(get_the_ID(), ‘Sizes’, false);
foreach( $metas as $key => $value ) {
echo ‘$key = ‘ . $key . ‘; $value = ‘ . $value . ”;
}
and the result is
$key = 0; $value = 115/135
$key = 1; $value = 110/125
$key = 2; $value = 95/110
$key = 3; $value = 80/95
$key = 4; $value = 70/80
Well, my question is (sorry, I can’t get through this):
the values are S, M, L, XL, and XXL and the keys are 70/80, 80/95…
Where am I wrong?
Update of what I did:
I can’t retrieve data from the checkbox list. Following the example,
if I check ‘reading’, I can’t retrieve ‘Books’ and ‘Magazines’ by means of a php instruction…or actually I can’t do it.
So I did this:
$checkbox_list = get_post_meta(get_the_ID(), ‘prefix_checkbox_name’, false);
switch ($value){…}
but I think this is not correct.
If anyone can help, it would be appreciated a lot.
Thank you.
Ooops, I forgot one line
$checkbox_list = get_post_meta(get_the_ID(), ‘prefix_checkbox_name’, false);
foreach( $checkbox_list as $key => $value ) {
switch($value){…}
Hello,
I’ve been using your script recently – it’s amazing, thank you very much for it!
I was wondering if it’s possible to have file upload/manage functionality that would upload into a specified folder on the server rather then media library?
I would really appreciate any tips or help with this.
Many thanks,
Dasha
I love your Class, it’s the only one I’ve found that makes it easy to add images to a metabox.
Any suggestions on how to extend your class to allow for dynamic metakeys? I’m looking for the functionality that allows a user to create multiple instances of the same metabox for a rental building available space page.
I’m basically looking for the functionality from this script, but in a class that can be used for multiple metaboxes.
http://wordpress.stackexchange.com/questions/4293/attach-files-metabox
Morning all. After a lot of search I found the solution by myself and after that the solution was right here in a comment in update2…
Anyway, I’m always working on checkbox list.
Every metabox has got a table in which I put dresses size.
If my post contains two or more metaboxes (different ids), and the sizes are equals (let’s say S for men and S for women correspond to different measure in cm), how can I select the right metabox?
I would like to have Metabox Men->S and Metabox Women->S
Thanks again
Sorry to be here again…is it possible to view all comments from all the people? We can see only the first or the last page.
Thank you again
Thanks for report. You can see all comments now.
I was wondering… how could I add a “Select all images” button or checkbox next to the “Insert selected images” button in the media uploader? I tried playing around with meta-box.js but couldn’t get it to select all the checkboxes. When uploading more pictures such a feature would come in handy.
Hope you can help.
Thanks,
Radu
Heads up.
Breaks the default text editor in WordPress 3.3 Beta 1…
Hopefully not too much of a problem.
Any chance the image uploader/gallery can use the same image across multiple posts, like the default WordPress featured image?
Currently once an image used in the meta box image, thats it no use elsewhere…
Still a cracking script, thank you :)
Hey buddy :)
Just a heads up. WordPress 3.3 trouble: metabox script’s wysiwyg textarea field causes tinymce crash on the editor.
Cheers,
Onur
Thanks Onur, I haven’t tested it with WP 3.3 yet. I’ll figure out this problem.
This is a fantastic Class – thankyou!
I was wondering if there was a way to set the number of rows in a text area? The style option is not working for me.
‘style’ => ‘width: 200px; height: 80px’
Thankyou.
The “style” attribute is deprecated in version 3.2.2. Instead, you can use CSS rule to style it.
Hi,
I got the thumbnails to layout fine, but how do I link them to their larger photos? I’ve used your image display code exactly as above, of course changing the meta_id value. Ideally, I would like to use the fancy box plugin to display a lightbox for these images.
Any suggestions?
Thanks.
In the code of getting image thumbnails wp_get_attachment_image_src($att, ‘full’); you just change “full” to “thumbnail” or another image size to get the other version. Of course you can use 2 calls to get 2 versions of images, and then you can apply them for Fancy box.
Thanks for your input. I used “thumbnail” instead of “full” and the thumbs come up fine, just can’t link to their larger image. Here’s my code thus far:
get_col("
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment'
AND ID in ($meta)
ORDER BY menu_order ASC
");
foreach ($images as $att) {
// get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
$src = wp_get_attachment_image_src($att, 'thumbnail');
$src = $src[0];
// show image
echo "";
}
}
?>
Dang, my code didn’t come through. Here it is: http://pastebin.com/N04PFsMh
i get a layout error in WP3.3 Beta 1 :(
Hiya,
I’m getting problems deleting file uploads/attachments.
The files upload without problems but if I try to delete I get a permissions error “You do NOT have permission to delete this file”
After the warning if I Publish or do a refresh the file reference does get deleted from the database but not the file on the the server.
Hope that makes sense – any suggestions?
Guys, we have a problem:
wp-admin/includes/deprecated.php
*/
function wp_tiny_mce() {
_deprecated_function( __FUNCTION__, ’3.3′, ‘wp_editor()’ );
My quick solution – at least until this problem will be resolved – I gave up to tinymce and used ckeditor instead
I am working on a plugin that uses not one, not two, but SEVEN editors on the same page, and all of them are working just fine
Download CKEditor (http://ckeditor.com/) and paste the “ckeditor” folder in the same folder with all other files (meta-box or whatever you rename it)…
// load the editor script
wp_enqueue_script('ckeditor', $base_url . '/ckeditor/ckeditor.js');
function show_field_wysiwyg($field, $meta) {
$this->show_field_begin($field, $meta);
echo "$meta
CKEDITOR.replace( '{$field['id']}' );";
$this->show_field_end($field, $meta);
}
OH, crap!
Here’s the code:
http://pastebin.com/PAxN7DV5
I came across your website through Google, and just wanted to say this is EXACTLY what I as looking for. In fact, I am pleased to say, it is MORE than I was looking for. This is a GREAT contribution for many WordPress Developers. Definitely recommending this post. Thank you for your continuous efforts in making WordPress a better solution for website owners!
Hello All ,i get an error when i am trying to delete an uploaded image through meta-box field image. my meta-box array is
$meta_boxes[] =
array(
‘id’ => ‘pContent’,
‘title’ => ‘Portfolio Image’,
‘pages’ => array(‘portfolio’),
‘include_id’ => array(”),
‘context’ => ‘normal’,
‘priority’ => ‘high’,
‘fields’ => array
(array
(‘name’ => ‘Add Image’,
‘desc’ => ”,
‘id’ => $prefix . ‘p_images’,
‘type’ => ‘image’,
‘std’ => ”,),));
this meta-box is added on a custom post type “portfolio”. When an image is attached with the post, a delete link is show on the thumbnail, and when i click on the delete link its pop up a error box says, “You do NOT have permission to delete this file.”
Please help me in this matter.
Deleting images works fine for me, maybe it’s a permissions issue for others? It’s worth noting that I didn’t mess with the image upload script, other than adding my own values.
I’m having problems with saving the added image. For new posts it works fine, adding pictures to existing posts also work.
But sometimes it fails and no image is showed. Whats the problem here?
Impressive script, thanks for the effort!
Small but nice improvement on the validation part would be to also pass the $field array to the custom validation functions (to get the fields ID or default value).
In version 3.2.2 I changed line 416 to:
$new = call_user_func(array(‘RW_Meta_Box_Validate’, $field['validate_func']), $new , $field);
Still an impressive script!
But there seems to be small problem with default values of checkboxes.
In version 3.2.2 at line 226 the function show() checks if a custom field has any value: if not, it declares the default value. See:
$meta = ($meta !== ”) ? $meta : $field['std'];
But when a checkbox is unchecked, no data is saved and the next time the field gets loaded, it gets the standard value. If the default value is 1, true, ‘on’ or ‘checked’ an unchecked checkbox always automatically gets checked again!
A solution might be to always save a value, also when a checkbox is unchecked. Like FALSE, 0 or ‘off’…
You’re right. Can you please raise an issue on Github (where the new version is being developed)?
Hi Rilwis, I just did. See https://github.com/rilwis/meta-box/issues/6
Will you have any future plans to develop an image upload with link?
That would be very handy :)
I’m using WP 3.1.4, with Rilwis’s 3.2.2 class. The native “insert into post” function to add pictures to the editor is no longer works.
Thanks Paul!
In my version of the class I have separated ‘value’ from ‘titles’ in the select option, like this ‘options’ => array($option['values'], $option['titles']).
When selecting a list of posts for example, you want to save the ID but show the post title.
Can you add it to the class in the future?
Hi Jens,
You can show that simply by assign the ‘options’ => array( ‘id1′ => ‘title1′, ‘id2′ => ‘title2′ ); without adding extra PHP code to the class.
You don’t have to accept this comment but here is my code I used.
echo “”;
foreach ($field['options'][0] as $key => $value) {
echo “$value”;
}
echo “”;
Hi, is it just me or the ‘image’ metabox type doesn’t show uploaded images?
Using WP 3.2.1
Hi there
I am trying to use this plugin with another plugin “cf image gallery” http://wordpress.org/extend/plugins/cf-image-gallery/
I can upload and view images using your code on my page, but i am trying to get the images into the cf gallery plugin
here is a snippet of the code with some of the options ive tested. The original cf image gallery code displays images attached to posts, but when I try and substitute my own key (rw_code) it doesnt seem to work. (you can see my commented out tests) rw_code works fine in your code to show images on the page. It just doesnt work when I put it into the cf image gallery plugin.
I need someone familar with arrays and syntax to take a look if possible? Ive put in various print_r to let me see what the arrays contain.
function get_cf_value($cf_key) {
global $post;
$cfs = $this->cfs;
$args = $this->args;
print_r ($cf_key);
// $meta = get_post_meta(get_the_ID(), ‘rw_code’, true);
$meta = get_post_meta($post->ID, $cf_key, true);
//$meta = get_post_meta(get_the_ID(), ‘rw_code’, false);
//$meta = get_post_meta(get_the_ID(), ‘rw_code’, true);
print_r ($cf_key);
if (!$meta) return NULL;
//$img['key'] = $cf_key;
//$img['value'] = $cfs[$cf_key][0];
$img['alt'] = nl2br($cfs[$cf_key . ' *alt'][0]);
$img['title'] = nl2br($cfs[$cf_key . ' *title'][0]);
$img['caption'] = nl2br($cfs[$cf_key . ' *caption'][0]);
$img['caption_html'] = ”.$img['caption'].”;
//print_r ($img);
// get img tag
$img['thumbnail']['html'] = wp_get_attachment_image($meta, $args['thumbnail_image_size']);
if (!$img['thumbnail']['html']) return NULL;
etc
Xin chào!
Tôi đang thử code của bạn trên wordpress beta phiên bản 3.2.2
Code của bạn bị lỗi ở đâu đó. Và nó phá vỡ cấu hình khi đăng bài.
Rất mong bạn sẽ nâng cấp và sửa lỗi trong thời gian gần nhất
Xin cảm ơn.
Hiện thời script này chưa được sửa lỗi đối với bản WP 3.3 beta. Tôi dự tính sẽ sửa lỗi 1 loạt khi WP 3.3 chính thức phát hành.
dont worry I worked it out. I was using one array to add several images, so of course all the images had the same meta ID. Which is why only one image showed up in the gallery as the gallery works through reading the ID
Now I have 3 arrays each with its own ID so now it all works fine.
hi Rilwis! I have a question… this is the code:
array(
‘name’ => ‘Ubicazione’,
‘id’ => $prefix . ‘ubicazione’,
‘type’ => ‘checkbox_list’,
‘options’ => array(
‘ubcentrale’ => ‘Centrale’,
‘ubdirettamentesulmare’ => ‘Direttamente sul Mare’,
‘ubfrontemare’ => ‘Fronte Mare’,
‘ubvicinanzefiera’ => ‘Vicinanze Fiera’,
‘ubvicinoaereoporto’ => ‘Vicino Aereoporto’,
‘ubvicinoalmare’ => ‘Vicino al Mare’,
‘ubvicinoautostrada’ => ‘Vicino Autostrada’,
‘ubvicinostazione’ => ‘Vicino Stazione’,
),
‘multiple’ => true,
‘desc’ => ”
),
Then i put that code for retrive multiple checkboxes list:
If i have selected for example “Centrale” and “Direttamente sul Mare” in my page i show:
ubcentraleubdirettamentesulmare
Is possibile to show “Centrale” and “Direttamente sul Mare”? with space separated or for example with a list?
Many thanks in advance!
Hi, I think you should swap the ‘key’ => ‘value’ pairs, or using the same value for both of them. The script will save the ‘key’, and display the ‘value’ in meta box.
Advanced Meta Box Class
the link doesnt work any more, does anyone have a copy or a link to download?
thanks
Yeah, I noticed that, also.
Rilwis, could you contact Manny to see if he could move his script to a different host?
OK, I’ll contact him. Hope he’ll be back soon.
ok thanks, I just logged in here to find the script and the link is working :)
when added to my custom post type and then cpt called in backend i get the error ‘”this.farbtastic” is not a valid function’. this is a problem in code listed under colorpicker call, and furthermore the image button and colourpicker simply return a value of “#” and therefore jump to the top of the page each time one of them is clicked. can you let me know what i am missing? thanks.
thanks for this script, ive been using it for a while. i just turned on wp debug (for the theme i am creating) and found an error in the show_field_image() function.
the sql query is being run even if there arent images, and throwing an error.
this is caused by the follwing line in the function (line 323):
if (!is_array($meta)) $meta = (array) $meta;
you then later use an if not empty:
if (!empty($meta)) {
but this returns as true because you have defined the variable as an array (not sure if this is correct or not)
ive simply commented the:
if (!is_array($meta)) $meta = (array) $meta;
out of the code and the functionality is still fine, but the error is removed.
thanks again for this great class i will continue to use and it is a core part of my wordpress themes.
Thanks Lee, I’ll keep watching on this. Looks like a strange bug ;)
For some reason when I upload an image it registers the upload (It adds it to the media library), but once I save the post it doesn’t save the image.
I’m using it with WP 3.2.1 and on a custom post type.
Any ideas?
Same issue. Any thoughts?
To confirm I have deactivated all plugins and there doesn’t seem to be a conflict.
The strange thing is it was working fine. I was publishing posts and uploading images just fine this morning and then out of the blue all the images I had previously attached disappeared.
I checked Firebug and I do seem to have a problem with my script
“NetworkError: 404 Not Found – ***/wp-content/themes/iko_responsive/library/meta-box.js”
However I think this is a side issue as I was having difficulty queuing scripts earlier. In my header the “meta-box.js?ver=3.2.1″ IS there.
Please try a trick:
- Upload images, then close the uploader (without insert images)
- Click “Add images” again, navigate to “Gallery” tab, and insert images
Thank you so much. This works. Could there be a specific reason why this happened on my site or is it a common issue? Finally do I actually need to queue the scripts from my functions file or is it already handled by your script? I’m in a little bit over my head with this but learning a lot from it. Thanks again.
It’s a common issue. Actually, users always insert images by clicking on default “Insert to Post” button, but that’s not what I implement on this version (it worked on previous version).
In fact, I implement a multiple image insertion. Users need to upload multiple images, and then they’ll see a new button “Insert images”. That’s it.
If user insert only 1 image, they should go to the Gallery tab and insert that image.
And by the way for anyone else with this issue – I was adding images from a URL initially but will continue to upload them instead as this fix seems to work fine.
Great Script!
The one issue I found was when using child themes, I could not define new meta boxes at the child theme level since the script was added to the parent theme’s functions.php level.
To overcome this, I have packaged the script up as a plugin, allowing the class to be created before the theme functions are run, so the class is available at both the parent and child theme level. This also allows the class to be portable between themes.
In the process of submitting the plugin to WordPress, but until then, you can download the RW Meta Box Class plugin at http://ednailor.com/wp-meta-box-class
Thanks Ed for wrapping it as a plugin. Actually that’s what I’m doing in version 4.0. I’m also submitting it to WP repository as well :D. If you’re interested in, please join the project at GitHub and collaborate on it. Thanks.
Hi Rilwis, do you think it’s possible to supply version 4.0 without being a plugin? It would be extremely handy to include in templates just like we would do with version 3.2x.
Thanks in advance.
The new version requires only 2 lines of code to make it run within a theme. It’s still easy. Here’s the docs.
Thanks man. You’re the best!
Hi Rilwis!
have a question….
i use that for list all users as dropdown list
$users = get_users(‘orderby=nicename’);
$myusers = array();
foreach ($users as $user) {
$myusers[$user->ID] = $user->display_name;
}
and placed here:
array(
‘name’ => ‘Cliente Registrato’,
‘id’ => $prefix . ‘lista_utenti_hotels’,
‘type’ => ‘select’,
‘options’ => $myusers,
‘std’ => ”
)
but when i go to call them with get_post_meta that not return the value but the key
it return 1-2-3-4-5…. for example… i want to return the name of the author… is possible? Thanks!
Just change your code to $myusers[$user->display_name] = $user->display_name;
Thanks Rilwis work great now! :)
I love this script of yours and have been using it on some of my recent projects. Always nice to have some presets.
I have not looked into it yet, but thought about giving you a heads up. On my local wordpress installation I’m running WordPress 3.3 beta 2 and there seems to be something going wrong when using the wysiwyg editor meta field. The editor of the main screen and on the meta box seem to disappear. When typing into the meta-box it seems to act normal (add p and br tags automatically).
If i have the time i might look into it myself, but wanted to let you know so you could potentially fix it before WordPress 3.3 comes out of beta.
Thanks again for your wonderfull script!
Hi Johan, this bug relates with the way WP generates WYSIWYG editor, which is totally new in v3.3. It was also reported to me, but I haven’t fixed it yet :(. I’m planning to fix it once the 3.3 is official released.
Hi Rilwis,
Thanks for the hardwork on the script it works great!
Recently, I encountered a problem with WP 3.2.1. This is for image uploading. The problem happens after I go to Media > Settings and click “Save Changes”.
What happens next is the database table “wp_options”, option_name “image_default_link_type” gets updated from “file” to “”.
This renders the “Insert Selected Images” from the image meta box useless, you can no longer insert the image although the image is sitting within your uploads folder.
My quick fix for now is to manually update the option value back to “file”.
Thanks again for the hardwork
Jie
Is there any way to modify the WYSIWYG editor to allow 1) Images inserted like the main image WYSIWYG on normal post types and 2) the HTML tab on this WYSIWYG meta box?
Thanks!
Hi Tran,
I just gave to you a small donation to say thanks for your script. :)
Keep up your awesome work!
Thank you very much!
Here’s a quick and nasty way to add a visual/html switcher to the custom meta boxes…
function tinymce_add_code() {
// Don’t bother doing this stuff if the current user lacks permissions
if ( ! current_user_can(‘edit_posts’) && ! current_user_can(‘edit_pages’) )
return;
// Add only in Rich Editor mode
if ( get_user_option(‘rich_editing’) == ‘true’) {
add_filter(‘mce_buttons’, ‘register_tinymce_code’);
}
}
function register_tinymce_code($buttons) {
array_push($buttons, “code”);
return $buttons;
}
// init process for button control
add_action(‘init’, ‘tinymce_add_code’);
It adds a blue ‘html’ button which opens up the html editor in a thickbox.
Hi,
I can use texts with a code like this “php ec dollar sign fname” in while but when i upload an image or a file this process is not so successful. What is the exact code i need to use when i want to upload screenshot using uploader?
Thanks in advance,
Sean
p.s.: this is my 3rd message cause i couldnt manage to make the codes appear in message
Hi Anh Tran my friend! Remember me? Giovani from pixeltemple.com, the pixels guy! Can you help me with an issue? I must be doing something wrong here…
Using your meta-box script everything is working pretty fine, except for one single problem… There is no way for me to query a custom post with a specific taxonomy and term created by your script.
Let me explain:
Using the plugin CustomPostType UI, I do register my post type: “Publications”. Then, using your metabox script, I add a metabox called “publi-status” to my “Publications”. The status could be “Coming Soon” and “Out of print”. Then, I try to query the posts as this way:
new WP_Query( array( ‘post_type’ => ‘publications’, ‘taxonomy’ => ‘publi-status’, ‘term’ => ‘out-of-print’ ));
No results…
I tried also:
get_posts(‘post_type=publications&taxonomy=publi-status&term=out-of-print’);
No results…
I tried too:
get_posts(‘post_type=publications&publi-status=out-of-print’);
No results…
BUT, if I perform a traditional query as:
get_post(‘post_type=publications’)
and when I do check the meta-value using:
get_post_meta(get_the_ID(), ‘publi-status’, true);
the result is CORRECT! The value is really registered, and it is definetely there! What should I do to make this work on a reular query_post method?
Do you have any ideas?
Thanks!
Regards from Brazil,
Giovani
Oooh myyy!
I just figured it out right now that I was searching on the completely wrong approach! I can’t query by taxonomy since the metaboxes register META VALUES! I found a solution to my problem doing the following:
$args = array(
‘post_type’ => ‘publications’,
‘meta_query’ => array(
array(
‘key’ => ‘publi-status’,
‘value’ => ‘out-of-print’,
)
),
‘orderby’ => ‘title’,
‘order’ => ‘ASC’
);
$query_publi = new WP_Query($args);
And then you perform the normal WP loop.
I hope this snippet helps someone else!
Regards,
G.
Hi rilwis,
The script is great and works a charm!
There’s one issue that I’m having: all the meta boxes created are nesting within each other. It looks like there’s one closing div tag missing from the generated code.
Can you help?
Hi Alex, I’ve just checked the script on Chrome and IE8 but didn’t see the problem. Which browser are you using?
I have the same prob… in chrome and FF.. seems to only occur on checkboxes… looking into it now.
I am seeing this issue too. It seems that when a checkbox is in the meta box (using the first demo meta box example) the closing div for that rwmb-field isn’t being inserted.
Using Chrome 15 on Win7.
Otherwise this plugin is great!
Thanks
Just updated the script to v4.0.1 with fix. Thanks for reporting.
Thanks for the update!
rilwis please delete the above statement as it stripped some code.
In inc/fields/checkbox.php add an end div tag after the end span tag in the static function end_html
Ah, I got it. The fix is going on its way!
Just a suggestion of mine for the next update:
I noticed that the text field has a default size of ’30′. I do realize the width of the input can be easily changed with css, but still, it’d be nice if we could add an option for the size in the array.
I made it work on my website, but i’m sure it’ll not survive an update, so that’s why i’m suggesting it.
On the file ‘/wp-content/plugins/meta-box/inc/fields/text.php’, i made these changes:
if ($field['size'] == ”) { $field['size'] = ’30′; }
return “”;
This way, we CAN define our own size for each text field, and in case we don’t do it, the core will put it to the default, 30. =)
The same could be done with the textarea.php file:
if ($field['cols'] == ”) { $field['cols'] = ’60′; }
if ($field['rows'] == ”) { $field['cols'] = ’10′; }
return “$meta”;
Both small changes that hurt nobody with previous versions of your script, and will add an extra functionallity. I hope you approve this. Thank you for reading anyway =)
Hmmm it seems that my comment got the html parts missing. Lemme try again.
Fix for the text.php file:
if ($field['size'] == ”) { $field['size'] = ’30′; }
return “<input type=’text’ class=’rwmb-text’ name=’{$field['id']}’ id=’{$field['id']}’ value=’$meta’ size=’{$field['size']}’ />”;
Fix for the textarea.php file:
if ($field['cols'] == ”) { $field['cols'] = ’60′; }
if ($field['rows'] == ”) { $field['cols'] = ’10′; }
return “<textarea class=’rwmb-textarea large-text’ name=’{$field['id']}’ id=’{$field['id']}’ cols=’{$field['cols']}’ rows=’{$field['rows']}’>$meta</textarea>”;
Heh, i’m glad html special chars worked here. Well, that’s it. Thanks. =)
Thanks. I’ve had the same problem with the closing div.
Also, would it be possible to easily change the jQuery theme (datepicker) from Pepper to something else?
The latest version (both on WP.org and GitHub) has a fix for closing div. Please update. Regarding the jQuery theme, currently, it’s hardcoded :(
Hey Rilwis! I just got stuck once again…
All my metaboxes are working fine (registering their values and delivering their values correctly), with exception of the IMAGES field.
On the very same metabox all other variantes work fine (TEXT, WYSIWYG, CHECKBOX), however the IMAGES return a empty array when I perform:
$meta = get_post_meta(get_the_ID(), ‘my-meta’, false);
print_r($meta);
And, of course, the images are being uploaded correctly and they are linked to the custom post.
Any idea?
Thanks!
In addition: I can grab the images normally as if they were simple regular attachments, however this does not work for me, since I need to get the specific images right from the specific meta-fields.
Thanks!
Ooooops again! Just found the solution! To have the “IMAGE” correctly registered, I need to press the INSERT IMAGE button. I was not doing that because I was thinking it could throw the image inside the regular post text field, situation which I am avoiding for my project.
If you want, please remove my comments.
Otherwise, let people read them!
Thanks Ahn!
Hey Mr. Rilwis, first of all, i’d like to really thank you for your plugin, it saved me a lot of time to create a smooth meta box for a job that i need to finish quickly.
Now, i’d like to ask a little help with IMAGE type field. I made some tests uploading like 3 images for the same field. They uploaded correctly and their thumbs appeared alright on the metabox. Awesome so far =)
But when i swap them, they do swap but the js throws an alert box with “undefined” on it.
Another problem is when i click on delete. The alert appears once again, but… it doesn’t delete the image =(
I’m using WP 3.2.1 with custom post type. And the last changelog on your plugin readme file is the 4.0 version.
Any insights of how i can fix this? Thanks in advance. =)
Please try the latest version. I think it’ll fix the problem.
Thanks for replying, Rilwis. Alright, i updated, and it… Did and also didn’t fix it =(
The alert won’t show anymore, but… i have two issues:
1) When i swap the images that i uploaded on the same field, even though i reorder them as i want to, after i hit “Update” it reset to the upload order.
2) Delete button won’t show alert (good) but also won’t delete, hehe.
Hmm, can you please try the plugin with a fresh install of WP. Maybe it’s because of other plugins or themes.
i was wondering if i could get your help on this great script. ive used it many times before, but im stuck this time.
i want to be able to add “tasks” to a custom posts type.
they way i wanted to do this is to have a new field type “tasks”.
this field would have a textarea/text input , a created date, and a completed checkbox. all in one field.
i want the user to be able to add a task, and then be able to click a “add another task” link, which would insert another task field underneath the existing one.
i wan the user to be able to add as many tasks as possible.
i know with your great script this can be done, but just cant get my head around how to do it?
Rilwis, i followed your advice trying with a fresh install, and i found out the reason.
Since i’m not well experienced with custom post types, i created one snagging just the “register_post_type” function of this plugin:
http://wordpress.org/extend/plugins/spots/faq/
And it seems that the problem with swapping / deleting thumbnails only happens when i’m using this post type. (Still, if i go to the post gallery and delete it from there, it works perfectly.)
Maybe it could be something on the properties of the post type, so here’s the code i’m using. I know i might be abusing of your free support by asking help on such a thing, but please, i love your plugin so much that i don’t want to abandon it just because of this minor glitch.
add_action( ‘init’, ‘create_post_type’ );
define( ‘SPOTS_POST_TYPE’, ‘spot’ );
function create_post_type() {
register_post_type( SPOTS_POST_TYPE, array(
‘labels’ => apply_filters( ‘spot_post_type_labels’, array(
‘name’ => _x( ‘Spots’ ),
‘singular_name’ => _x( ‘Spot’ ),
‘add_new’ => _x( ‘Add New’ ),
‘add_new_item’ => __( ‘Add New Spot’ ),
‘edit_item’ => __( ‘Edit Spot’ ),
‘new_item’ => __( ‘New Spot’ ),
‘view_item’ => __( ‘View Spot’ ),
‘search_items’ => __( ‘Search Spots’ ),
‘not_found’ => __( ‘No Spots found’ ),
‘not_found_in_trash’ => __( ‘No Spots found in Trash’
‘parent_item_colon’ => ”,
‘menu_name’ => __( ‘Spots’ )
) ),
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘show_in_nav_menus’ => false,
‘query_var’ => true,
‘rewrite’ => true,
‘exclude_from_search’ => true,
‘capability_type’ => ‘page’,
‘has_archive’ => false,
‘hierarchical’ => false,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘custom-fields’ ),
‘taxonomies’ => array( ),
‘register_meta_box_cb’ => array( &$this, ‘meta_boxes’ ),
‘_edit_link’ => ‘post.php?post=%d&post_type=’ . SPOTS_POST_TYPE // generally frowned on but needs some custom CSS
) );
}
Thank you for this script, I appreciate the time you’ve put into it.
I was wondering, is there a way to have different terms saved from within the same hierarchical taxonomy, using different meta boxes for each cluster?
Example using the default Category taxonomy:
`Category
-Parent1
–ChildA
–ChildB
–ChildC
-Parent2
–ChildX
–ChildY`
At the moment I can show Parent1 and Parent2 with their terms by duplicating the example ‘Categories’ metabox, altering their `id` and specifying the `parent` argument.
However only the last term selection is saved – Parent2′s in the above example. I assume some looping is needed but my mind can’t handle it!
I realise there’s also the choice of using a different taxonomy for each Parent-Children cluster but there are some cases that it’s best if they are under the same “roof”.
Hi, did you set the different field IDs?
Hey Rilwis, i noticed that maybe i asked too much =( That’s so sad.
Anyway, can you just point to me where is the code that deletes the file?
Maybe i can try digging on it and even force a workaround just to make the delete button work. I’m really in need to make it work.
Thanks in advance.
I did it. I managed to make it delete the attachments even though it now requires a page loading, using the wp_delete_attachment function. Just ignore my question ;)
This looks awesome, my only question. IT says it is a plugin so does that mean it must be installed as a plugin or can it be added into my themes code without requiring a user to install this plugin?
Hi Jason. Of course you can include it into your themes. I wrote a wiki page for that here.
is there a way to limit image upload to only one file?
or maybe, include both way of upload, old version and this new version…
Smrth, you mean ALLOW the user to have only one image per image item or unallow him to add new upload buttons?
allow the user to have only one image per image field.. i.e. upload only one image not more…
I’m also curious about this. I want to have an image upload field that only allows the user to upload one image. I think it would make it a better user interface if there’s a spot where one image can be replaced and in the back end the user can only upload one image. Having the ability to upload several when the fron end is set to only use one might tick off a user. . .
Rilwis,
With the upgrade to 3.3, the HTML editor box is no longer working. What are the current plans to upgrade the script to include the new editor box function that 3.3 ships with? Any quick fix for the time being? I have a site going live for a client tonight, and if I make it live with 3.3, it will kill one of the features they need to work a CPT.
Any information would be appreciated.
Thanks
Ed
Hello Ed,
You may wish to use the version hosted at GitHub for now. It includes this feature, and AFAIK is backwards compatible to previous versions of WordPress.
Hi Rilwis,
I’m loving your plugin very much, it has been a great help in creating better pages for my projects. I do have a suggestion for you. I’m using the ‘file’ type to upload a single file. However the admin area enables the user to upload many files instead. Could you perhaps add a different type for multiple files (e.g. ‘files’) or something like how many files you would like the user to upload?
something like:
‘type’ => ‘file’ // Field type: file upload
‘number_of_files’ => 1 // Number of files a user can upload, use ’0′ for infinite.
The reason is that enabling multiple file uploads could lead to expectations in the front-end and possible problems with retrieving the single (first file) in the list. Also I prefer to have my end-user get as clean an interface as possible.
That’s a nice idea. I’ll mark this as a next feature. Thank you very much :)
Agreed. I think this would be a fantastic addition.
Although it is a pretty AWESOME script as is!
Hey,
I noticed that the new version (V4) doesn’t support Media gallery uploads anymore. Do you plan to include this feature again?
Awesome script anyway :)
Yes, we have a plan to put the new media uploader (since WP 3.3) to meta box script.
Here’s maybe an odd question: Is it possible to easily add a CSS class to a meta box? I am trying to take advantage of WordPress’ built-in box toggling. Apparently, adding a class of ‘closed’ will cause a box to default to a closed state. Is there a better way to do this?
Actually, never mind the CSS class part of that last question. Turns out that won’t work. But I am still open to ideas for having metaboxes closed by default. When there are a lot of boxes, this could really help to keep things clean and manageable.
I’m a noob
I added demo.php to the themes folder
added the include in the functions.php
I see the meta box
I add text, I update the post
and I don’t see any thing form the meta box
on the post page when I select “view post”
I have another meta box plugin installed on another WP installation
and it works just fine
any suggestions?
thx
To display the value of meta box fields, please read this.
you just won the awesome competition for the week. Thanks for this script it’s saved me loads of time on a project I’m working on and I will definitely be using it again.
Can anybody help me with sliders class from Pippin Williamson?
thanks for this code, it has been a great help. i do have one thing that is puzzling me though….
I have 2 meta boxes both containing different image uploads that need to be displayed in different positions on the page. I am using the code below to pull out the images but am struggling to set the thumb of that image to display rather than the full size version… does anyone have any thoughts?
$my_meta = get_post_meta($post->ID,’rw_small_img’,TRUE);
if (!empty($my_meta)) {
foreach ($my_meta as $image) {
echo “”;
}
}
Rilwis, just checked out the new Meta Box script (beta) and its AMAZING! Took me a little while to figure it out without documentation, but I’m loving it. Its so easy to create custom meta boxes by simply creating a new file. Some of them are broken in 3.3, but super easy to re-write and fix now.
That’s cool :). We’re working on this script to make it better and better. Hope you can join us on Github :)
I am having problems using custom taxonomies when I use the dropdown (select) option. It displays fine my custom taxonomy on the dropdown but when I save, it saves a number instead of the term and it actually adds that number as a new element on the taxonomy.
Please help
Thanks!
Hi,
I am using the latest version of the plugin Meta Box and type slider doesn’t work.
How do I use it? I see a panel like this: http://dl.dropbox.com/u/5785988/slider.png
Thanks for the great code. One question though:
I’m trying to add the tiny MCE controls to a textarea meta box field I’ve created. Does anyone know how I can do this in WP 3.3?
I’ve spotted the code from Karl above, but if this works how do I implement it? I’ve trying dropping it into my functions.php but nothing happens.
Actually, the current version of Meta Box plugin works with new editor API of WP, it automatically adds controls, tabs, buttons, etc. to you
wysiwygfields. Please try it.Haha, apologies for my stupid comment. I didn’t see there was a wysiwyg option. Works a treat. Thanks for the the original code and reply.
Hi,
How can we implement this plugin directly within the theme? The Wiki link doesn’t work at the moment: https://github.com/rilwis/meta-box/wiki/2.01.-How-To:-Include-Meta-Box-Script-In-A-Theme
Oops, this is a mistake. Here’s the correct link.
First of all!!! A BIG thank’s for this script… But I’ve two question…
How can I display more than one result with the checkbox?
I have something like this:
array(
‘name’ => ‘Professeurs’,
‘id’ => $prefix . ‘professeurs’,
‘type’ => ‘checkbox_list’,
‘multiple’ => true,
‘options’ => array( // Options of checkboxes, in format ‘key’ => ‘value’
‘Mme X’ => ‘Mme X’,
‘M. Y’ => ‘M. Y’,
‘M. B’ => ‘M. B’,
‘M. N’ => ‘M. N’,
‘Mme V’ => ‘M. V’,
‘M. A’ => ‘M. A’
),
‘desc’ => ”
If i check more than one checkbox, it will be the firste which will be displayed and I want all…
Second question is about image… How can I display an uploaded image in my template (whatever is the way, plupload or type=’image’…)… I’m looking for that and my english make me unable for good understanding of the stuff there…
That’s all. For the rest, I’ve to tell you it’s an AMAZING script!!!
Hi Daneczech. I’m sorry but I’m not clear about your 1st question. Can you clarify it?
Regarding the 2nd question, I wrote a very detailed wiki page, and actually I don’t know how to explain better to you. So please try again and hope you will understand it.
Ok thank’s a lot man ;) Now everything’s ok ;) I didn’t foud this page before, it was helpful ;)
Hi,
When I upload an image, is there a way to get only this attached image URL? I have other images attached to post but I just want to get the URL of what I uploaded using the meta box.
Hi pixi, please follow this guide.
All my custom fields values should appear also in “Custom Fields box”… right?
Well is not… anybody knows why?
I checked and the values are stored in postmeta table!
Thanks,
I found it :)
in demo.php : * Wse underscore (_) at the beginning to make keys hidden
By the way is a spelling mistake: *Use underscore… :D
Hi thanks fro the script. Can I get my metabox to show only for certail wordpres3 postypes i.e video, audio etc? Many thanks
Apologies I mean WordPress 3 Post Formats i.e aside, gallery, link, video, audio etc. as opposed to custom post types so to recap I’d like individual meta boxes for wordpress 3 propriety post formats. Thanks
Love it, thank you! One question —
How can RADIO BUTTONS (with their associated labels) be on separate lines, so the options are all stacked vertically, as the Checkboxes are?
Hello people!
I’m a WordPress developer and translator (themes and plugins), from Brazil and I tried to translate this plugin, but translation doesn’t work!
I have created pt_BR.po and pt_BR.mo and put them into plugin’s /lang/ folder, but nothing happens!
Please, what I did wrong?
Someone help me!
Great plugin! I’m wodering… is there a way to set different meta boxes fom specific pages and/or posts of certain categories? Any tips on how to make this happen? Thanks so much!
Please, someone help me with my problem?
http://www.deluxeblogtips.com/meta-box-script-for-wordpress#comment-7410
Thanks in advance!
Miriam de Paula
wpmidia lab
Hi Miriam, the code has a bug for translation. I’ve just fixed it in the development version on GitHub. The current version on GitHub is not fully tested, so we still keep it on GitHub instead of WP.org. You can get it on GitHub to fix the translation now.
Hi,
I am using an older version of meta box script in few of my themes for clients. but Is there a way to use latest version of meta box script directly in theme files. As, I do not want to use it as a plugin due to some reasons…
Thanks.
You can read this document to see how to integrate the plugin within a theme.
Great.
You made my life easy :)
The new clone option is AWESOME! Any idea how we can clone an entire meta box ID and not just the fields? I am currently developing an event agenda builder and this would be extremely useful.
In theory, I would like the ability for both the meta box to be cloned as well as fields that are part of that meta box.
My logic is:
1) Day of Event would be the meta box ID. Could be cloned to create an unlimited amount of days for the event.
2) Fields could be cloned within the meta box (Day) to create the agenda line-item (time, title and description).
3) Any fields cloned within a meta box would be tied to that day.
A possible drawback is that each of my “fields” are actually 3 fields (time, title and description). I’m not exactly sure how I could get them to relate to each other so I could properly display them on the front-end.
Any ideas?
Hi.
How do you add meta boxes to a specific page ?
i tried with
if ($post_id == '2'), but it doesn’t work.When i try to get the id of the page I’m editing, WordPress is not able to return the id.
Any idea ? Thanks in advance