WPAlchemy MetaBox PHP Class
The WPAlchemy_MetaBox PHP class can be used to create WordPress meta boxes quickly. It will give you the flexibility you need as a developer, allowing you to quickly build custom meta boxes for your themes and plugins.
- Key Features and Benefits
- Defining a Meta Box is Easy
- Meta Box Setup Options
- The Guts of the Meta Box
- How to Use It! [+ show class methods]
- Filter Specific Templates, Categories, Tags and Posts
- Using The Meta Box Values In Your Template
- Download
- Contribute
Key Features and Benefits
- Easy to learn and integrate: good documentation and support is always important (I use the code myself and keep it up-to-date). Integration is a snap, as simple as including the class and using it.
- Easy setup code: some of the details involved in saving, retrieving and working with the meta data are abstracted to ease development.
- Flexible usage: the class acts as an aid for meta box development. By design you can use the class functions or your current development practices, which ever you feel most comfortable with for your development.
- HTML and CSS separation: the HTML and CSS for your meta boxes remain separate from the core code, you can design your meta boxes to your liking, providing you the greatest flexibility during development.
Defining a Meta Box is Easy
1 2 3 4 5 6 7 8 9 10 11 | include_once 'WPAlchemy/MetaBox.php'; // include css to help style our custom meta boxes if (is_admin()) wp_enqueue_style('custom_meta_css',TEMPLATEPATH . '/custom/meta.css'); $custom_metabox = new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php' )); |
That’s it! The above code shows the basic definition needed to setup a custom meta box.
Setup Options
The following are the different setup options that you can use in the initial class setup array:
id
id => '_custom_meta'
Each meta box that you create requires an ID, this is the value that is saved into the wp_postmeta table. Starting your name with an underscore will effectively hide it from appearing in the custom fields area.
title
title => 'Custom Meta'
This is the title of the meta box that appears in the WordPress UI.
types
types => array('post','page')
This will default to post and page types, to add your meta box to custom post types you must define the types option.
context
context => 'normal'
The part of the page where the edit screen section should be shown (‘normal’, ‘advanced’, or ‘side’).
priority
priority => 'high'
The priority within the context where the meta box should show (‘high’ or ‘low’).
template
'template' => TEMPLATEPATH . '/custom/meta.php'
You must define a template file for the contents of your meta box.
exclude_… and include_…
exclude_template exclude_category_id exclude_category exclude_tag_id exclude_tag exclude_post_id include_template include_category_id include_category include_tag_id include_tag include_post_id
Read more about Filtering Specific Templates, Categories, Tags and Posts
The Guts of the Meta Box
You probably noticed that the actual contents of the meta box come from the meta.php file. I’ve decided to leave the meta box content definition up to you vs having the class create form fields (this should give a you more freedom to manipulate the meta box contents to your liking).
Lets review the different parts to this solution, first off the meta.php:
How to Use It!
All of the functions in this class are very WordPress friendly. If you are familiar with the WordPress Loop, you should have no problem using this class.
When working on your meta box template file (meta.php) there are a few variables available to you:
$post; // this is the current post, use $post->ID for the current post ID $metabox; // this is the meta box helper object $mb; // same as $metabox, a shortcut instead of writing out $metabox $meta; // this is the meta data
Lets go over the different functions available in the class and how to use them. Important: you should refer to the meta.php HTML example above by using the line numbers given below. This should help you see the code in action.
the_field($name)
Use this function to set the current working field:
16 | <?php $metabox->the_field('description'); |
the_name([$name])
This function will print the form field name. If you’ve set the current working field with the_field($name) then you can simply do the following:
17 | $metabox->the_name(); |
If you have not set the current working field prior to calling this function, you can manually pass in a field’s name:
9 | $metabox->the_name('name'); |
get_the_name([$name])
Same as the_name([$name]) except that it returns a value instead of printing out the value.
the_value([$name])
Use this function to get the current value of the field.
17 | $metabox->the_value(); |
If you have not set the current working field prior to calling this function, you can manually pass in a field’s name:
9 | $metabox->the_value('name'); |
get_the_value([$name])
Same as the_value([$name]) except that it returns a value instead of printing out the value.
54 | if ($metabox->get_the_value() == '_self') echo $selected; |
the_index()
Used inside have_fields() and have_fields_and_multi() to print the current index number.
get_the_index()
Same as the_index() except that it returns a value instead of printing out the value.
is_first()
Used inside have_fields() and have_fields_and_multi() to check if the field group is the first field group. When using the_group_open() and the_group_close(), the first HTML element will automatically have a css class of first.
is_last()
Used inside have_fields() and have_fields_and_multi() to check if the field group is the last field group. When using the_group_open() and the_group_close(), the last HTML element will automatically have a css class of last.
is_value([$value])
Uses to check the existence of a value.
106 | <input type="radio" name="<?php $mb->the_name(); ?>" value="admin"<?php echo $mb->is_value('admin')?' checked="checked"':''; ?>/> Admin |
The above would be equivalent to:
106 | <input type="radio" name="<?php $mb->the_name(); ?>" value="admin"<?php echo ($mb->get_the_value() == 'admin')?' checked="checked"':''; ?>/> Admin |
have_fields($name,$length)
This function is used during a loop. It helps you create multiple instances of a field or group of fields.
23 | while($metabox->have_fields('authors',3)) |
Inside of the loop you can use the_name() and the_value() to help you define your form fields.
23 24 25 26 27 | <?php while($metabox->have_fields('authors',3)): ?> <p> <input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/> </p> <?php endwhile; ?> |
The above is equivalent to writing:
<p> <input type="text" name="_custom_meta[authors][0]" value="<?php if(!empty($meta['authors'][0])) echo $meta['authors'][0]; ?>"/> </p> <p> <input type="text" name="_custom_meta[authors][1]" value="<?php if(!empty($meta['authors'][1])) echo $meta['authors'][1]; ?>"/> </p> <p> <input type="text" name="_custom_meta[authors][2]" value="<?php if(!empty($meta['authors'][2])) echo $meta['authors'][2]; ?>"/> </p>
Another really cool thing you can do with have_fields($name,$length), is to define field groups like the following representation:
_custom_meta[links][0][title] _custom_meta[links][0][url] _custom_meta[links][0][nofollow] _custom_meta[links][0][target]
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <?php while($metabox->have_fields('links',5)): ?> <p> <?php $metabox->the_field('title'); ?> <input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/> <input type="text" name="<?php $metabox->the_name('url'); ?>" value="<?php $metabox->the_value('url'); ?>"/> <br/><?php $metabox->the_field('nofollow'); ?> <input type="checkbox" name="<?php $metabox->the_name(); ?>" value="1"<?php if ($metabox->get_the_value()) echo ' checked="checked"'; ?>/> Use <code>nofollow</code> <?php $selected = ' selected="selected"'; ?> <br/><?php $metabox->the_field('target'); ?> <select name="<?php $metabox->the_name(); ?>"> <option value=""></option> <option value="_self"<?php if ($metabox->get_the_value() == '_self') echo $selected; ?>>_self</option> <option value="_blank"<?php if ($metabox->get_the_value() == '_blank') echo $selected; ?>>_blank</option> <option value="_parent"<?php if ($metabox->get_the_value() == '_parent') echo $selected; ?>>_parent</option> <option value="_top"<?php if ($metabox->get_the_value() == '_top') echo $selected; ?>>_top</option> </select> </p> <?php endwhile; ?> |
have_fields_and_multi($name)
This function is similar to have_fields($name,$length). You will notice that it does not use the $length parameter. But it provides additional functionality. It allows you to setup a custom “add” HTML element that can be used to create unlimited copies of your field or field group.
A simple example would be a meta box for adding a list of links: you may have two fields, one for a title and the other for a URL, using the features of the class you can easily setup an “add new link” button which would automatically spawn new instances of the field group you defined. Basically, clicking the “add new link” button again would spawn another field group, and so on.
The following is an example of using this function:
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | <h4>Documents</h4> <a style="float:right; margin:0 10px;" href="#" class="dodelete-docs button">Remove All</a> <p>Add documents to the library by entering in a title, URL and selecting a level of access. Upload new documents using the "Add Media" box.</p> <?php while($mb->have_fields_and_multi('docs')): ?> <?php $mb->the_group_open(); ?> <?php $mb->the_field('title'); ?> <label>Title and URL</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <?php $mb->the_field('link'); ?> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <?php $mb->the_field('access'); ?> <p><strong>Access:</strong> <input type="radio" name="<?php $mb->the_name(); ?>" value="admin"<?php echo $mb->is_value('admin')?' checked="checked"':''; ?>/> Admin <input type="radio" name="<?php $mb->the_name(); ?>" value="editor"<?php echo $mb->is_value('editor')?' checked="checked"':''; ?>/> Editor <input type="radio" name="<?php $mb->the_name(); ?>" value="subscriber"<?php echo $mb->is_value('subscriber')?' checked="checked"':''; ?>/> Subscriber <a href="#" class="button" style="margin-left:10px;" onclick="jQuery(this).siblings().removeAttr('checked'); return false;">Remove Access</a> <a href="#" class="dodelete button">Remove Document</a> </p> <?php $mb->the_group_close(); ?> <?php endwhile; ?> <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-docs button">Add Document</a></p> |
the_group_open([$tag])
This function is used to create a container element around your fields, by default the HTML tag used is a DIV. The HTML element will be printed out.
95 | <?php $mb->the_group_open(); ?> |
get_the_group_open([$tag])
Same as the_group_open([$tag]) except that it returns a value instead of printing out the value.
the_group_close()
This function is used to close the container element around your fields. The HTML element will be printed out.
114 | <?php $mb->the_group_close(); ?> |
get_the_group_close()
Same as the_group_close() except that it returns a value instead of printing out the value.
Creating an “Add” Button
This button is used to create new instances of your field or field group. Adding a docopy-GROUPNAME css class to an HTML element will make it clickable. GROUPNAME is the name you used in the have_fields_and_multi($name) function.
117 | <p><a href="#" class="docopy-docs button">Add Document</a></p> |
Creating a “Delete” Button
This button is used to remove and instance of your field or field group. Adding a dodelete css class to an HTML element will make it clickable. This button has to be between the_group_open() and the_group_close().
111 | <a href="#" class="dodelete button">Remove Document</a> |
Creating a “Delete All” Button
This button is used to remove all instances of your field or field group. Adding a dodelete-GROUPNAME css class to an HTML element will make it clickable. This button does NOT have to be between the_group_open() and the_group_close(). GROUPNAME is the name you used in the have_fields_and_multi($name) function.
88 | <a href="#" class="dodelete-docs button">Remove All</a> |
The “remove” and “remove all” buttons are optional. You can still delete fields by simply deleting their values and clicking the post “Update” button. Important: Adding and removing elements will always require you to click the post “Update” button.
Filter Specific Templates, Categories, Tags and Posts
I often find myself creating meta boxes which apply to a specific template or post. With this class, you to filter your meta boxes a few different ways: by template file, category_id, category name/slug, tag_id, tag name/slug and post_id.
When creating a new WPAlchemy_MetaBox instance the following options are available:
exclude_template exclude_category_id exclude_category exclude_tag_id exclude_tag exclude_post_id include_template include_category_id include_category include_tag_id include_tag include_post_id
When assigning values to these options you can assign a value as a single value, an array, or a comma separated list. You will see usage examples below.
You can use as many options to achieve the results you want. Use the exclude options exclusively or the include options exclusively or combine them both for more advanced filtering.
It might be helpful to keep the following in mind: the excluding and including will be processed in the order listed above, excludes are processed first and then includes are processed, additionally templates come before categories which come before tags which come before posts.
Using Exclude Options
The exclude options allow you to exclude a template, category, tag, or post from displaying the meta box.
The following example excludes the “product” template from displaying the meta box, however all other templates will display the meta box.
1 2 3 4 5 6 7 | new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php', 'exclude_template' => 'product.php' )); |
Using Include Options
The include options allow you to only include a template, category, tag, or post to display the meta box.
This is different from the exclude option, as only the item that you specify will display the meta box, everything else would be excluded.
In the following example, pages that use the “product” and “press” templates will be the only pages that display the meta box, all other templates would not display the meta box.
1 2 3 4 5 6 7 8 | new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php', 'include_template' => array('product.php','press.php') // use an array for multiple items // 'include_template' => 'product.php,press.php' // comma separated lists work too )); |
Using Both Exclude and Include Options
For the most part you will do fine using exclude and include options separately from each other.
When you use exclude and include options together the include option will override any exclude options. Knowing this you can do some advanced filtering.
The following example will exclude all pages that use the “product” template except for a specific product page.
1 2 3 4 5 6 7 8 | new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php', 'exclude_template' => array('product.php'), 'include_post_id' => 85 )); |
More Exclude and Include Examples
The following filters your meta box to posts which have the “download” tag or is post_id 97
1 2 3 4 5 6 7 8 | new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php', 'include_tag' => 'download', 'include_post_id' => 97 )); |
The following filters your meta box by excluding it from several specific posts, unless those posts have a the “download” tag
1 2 3 4 5 6 7 8 | new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php', 'exclude_post_id' => array(45,48,56,57,88,91,92,93) 'include_tag' => 'download' )); |
The following filters your meta box to posts that belong to the “WordPress” category
1 2 3 4 5 6 7 8 | new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => TEMPLATEPATH . '/custom/meta.php', 'exclude_category' => 'WordPress', // 'exclude_category_id' => 12 // using category IDs also work )); |
Using The Meta Box Values In Your Template
Using meta box values in your templates is just as straight forward, in your template file you would do something like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | // get the meta data for the current post $custom_metabox->the_meta(); // set current field, then get value $custom_metabox->the_field('name'); $custom_metabox->the_value(); // get value directly $custom_metabox->the_value('description'); // loop a set of fields while($custom_metabox->have_fields('authors')) { $custom_metabox->the_value(); } // loop a set of field groups while($custom_metabox->have_fields('links')) { $custom_metabox->the_value('title'); $custom_metabox->the_value('url'); if ($custom_metabox->get_the_value('nofollow')) echo 'is-nofollow'; $custom_metabox->the_value('target'); } |
In the code above, $custom_metabox is the object variable you created in functions.php when you used new WPAlchemy_MetaBox.
Again, you are not limited to having to use the class functions, you can use the default WordPress function get_post_meta() as such:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // instead of using helper functions, you can also use ... $meta = get_post_meta(get_the_ID(), $custom_metabox->get_the_id(), TRUE); // or ... (same as above) // $meta = $custom_metabox->the_meta(); echo $meta['name']; echo $meta['description']; foreach ($meta['authors'] as $author) { echo $author; } foreach ($meta['links'] as $link) { echo $link['title']; echo $link['url']; if ($link['nofollow']) echo 'is-nofollow'; echo $link['target']; } |
Download
WPAlchemy MetaBox Class, this project is on github
Contribute
Are you using this class? If so, become a contributor to it’s growth and stability. If you have problems using it, definitely let me know (I like to write and use stable code). Equally, if you have ideas to make it even better, I want to hear that too.
{ 92 comments… read them below or add one }
First of all… Amazing explanation, this is going to solve a great deal of issues we have been having in simplifying the deployment of these metaboxes.
I have a few questions though which I am hoping you would be able to address or assist in resolving.
1) A problem we always run into even with wordpress 3.0 is the ability to show a metabox which allows you to show all the images and file attachments associated with a post. If you could somehow extend your plugin which would allow one to include and style the display of images it would be very very helpful (possibly using timthum to show the thumbnails of such images all with the same size). I am assuming this is probable a very simple addition (when dealing with images) but what would be excellent is if it would automatically also separate out any other files which might have been uploaded (again with the ability to style these). On the front end we have use the plugin attachment xtender which I remember worked fairly well.
2) As a separate point but expanding on the above request, I feel it would be highly valuable if the media upload capabilities could be somehow simplified while still using the word press media upload database structure. I personally find the default uploaded to be far to complicated for many users I have shown it to. My suggestion is a simple upload button one can add to a metabox with an optional URL input field… Clicking on the upload button would bring up your file browser where you can select one/more file and click save, this would then automatically upload each one through ajax with a progress bar online with the page, present a thumbnail and if defined in the metabox the applicable wordpress mediafields associated with that image. Now, if someone wants to modify an image such as cropping he can click the image or edit link which would bring up the standard wordpress media for that image. My logic here is that in nearly every situation this would be the absolute best way of doing things and your code here for meta boxes would allow so many individuals customize it to meet their needs.
3) These next few items fall outside the scope of your code a bit but I am hoping you have a solution for me and others as I have spent hours trying to resolve them.
A- I have been trying to find a way to directly influence the location of post meta boxes. What We have been looking for is a way to force the position of a meta box into a default location other than just priority of high. Additionally, if we were able to disable moving a meta box would be very helpful and being able to tell wordpress to reset the location of a meta box if it was moved by a user. On the same level I don’t know of a way to place a custom meta box above or directly below the default wordpress title.
B- do you know of a way to directly order (or reorder) the wordpress default menu items. Example- Through post types you can of course create a new admin menu but what I am unable to do is place such a menu item above the dashboard or for that matter change the location of the dashboard. There are plugins which allow this but I am hoping there is some simple code I can include in the functions file.
B-
First off, thank you! This PHP class helper is awesome, and greatly makes custom field creation easy! So thank you!
I do have a question concerning child themes. What can be done so that the required files/folders for WPAlchemy could be placed inside the child theme rather than the parent?
For instance I’m using Hybrid and if I want to use WPAlchemy I have to place the files in the Hybrid parent folder. I can still edit the functions.php file within the child to “activate” WPAlchemy. Though the meta files are in the parent theme folder.
Any ideas?
Scott, the WPAlchemy folder can be placed anywhere you would like, you just have to use the correct path to include the class file as well as the meta template file.
Great idea, thank you!
I decided to swap out TEMPLATEPATH with STYLESHEETPATH since I’m dealing with child themes.
Thanks again for the quick response.
Chris, thank you very much for your comments, your comment is a perfect example of the feedback that I am looking for.
preface: My ultimate goal for WPAlchemy is to make it a small and nimble framework built on top of WordPress, specifically designed for plugin and theme authors (and developers). Currently … the MetaBox class is just the first class in a group of classes that will comprise the framework.
#3A: this one I think actually falls within the scope of the code as it is functionality that directly relates to meta boxes and its general purpose.
#3B: I think this is a valid need and may be a new component all on its own WPAlchemy_AdminMenu(s) … I will give this one further consideration.
#1: I think this functionality actually falls outside of the scope of the class as it seems like a niche case to me, however I want to design the class with enough flexibility that anyone can include any additional libraries to use however they would like within their meta boxes.
Overly simplified solution: To do what you are describing within a meta box, I believe would not be too difficult, you would first need to get a list of images/attachements associated with the post, if these images are in the post content, you might have to parse the content and look for img tags, then you would use the timthumb lib and list out the images that were found. I have not yet explored the media uploader and its functionality enough to know how it stores is data and what data is available.
#2: I think this one also falls outside of the scope of the class, but I do agree with you that the media/file manager can be simplified, and perhaps this can become a specific component within the framework.
Overly simplified solution: again what you have described is totally doable, you would just have to include the needed libraries and simply create your own upload form field and handle the uploaded file (note: the class still needs a revision, something like a hook to allow developers to tap into the save routine of the class, in this case writing custom upload handler)
Hopefully this is the last question you’ll get from me.
Still concering child themes. Since the power of child themes lies in not touching the parent theme files. How do I go about calling field values from within the child themes functions.php? While true I could create a page.php in the child directory and call the value (ex. $custom_metabox->the_value(‘description’);) from there. But the child page.php would overwrite the parent’s page.php, which in my opinion defeats the purpose of a child themes.
All that to say, I’m trying to use an action hook to call the values directly from the child’s functions.php and I’m getting the following errer: Fatal error: Call to a member function the_value() on a non-object
Never mind, I’m an idiot. I was calling the value too soon. Like before the Loop too soon.
Also, if you are using theexample, you will have to access it globally doing something like the following:
$custom_metaboxinside of a function, per youradd_action('hybrid_after_content','imgurl'); function imgurl() { global $custom_metabox; echo $custom_metabox->the_value('imgurl'); }Thank you very much for your quick reply.
I greatly appreciate your suggestions on these topics.
Given your interest in additional features that might be needed here are some others which I have noticed although again they might not be related to this exact meta box functionality.
1) An issue which I recently ran into was that I wanted to create a custom taxonomy/meta box for “article source”. My objective was to essentially have a custom taxonomy were the items within it were essentially entries for different source publications (ie – The Washington Post). I goal was essentially very basic… just giving the editor the ability to pick from a drop down list of source publications so he could define the source. As I am assuming you are aware this is totally possible… the problem I ran into was that it seems I am unable to assign a meta box or additional custom field to a taxonomy. The goal here was to be able to assign additional fields for each taxonomy entry so I could for example add an image to each article source and have the site admin manage such sources all from one location. Do you think you can somehow modify your plugin to allow for this to happen? (Possibly remove the taxonomy description field and essentially have meta box values stores in there to use the default database structure)?
2) One area I got confused about related to the new exact and array storage functions you described. Recently I ran into an issue in which I wanted to use wordpress for a real estate site. The problems came into play when I was using custom fields to store property related attributes and then tried to create a public search which would query such entries. The problem was that it took very long to query the system ( I am assuming because the meta keys/values are not indexed individually)… So, my question here is does your solution somehow resolve this problem? If so, what are the side effects of your new storage system or when would it make sense to use your way?).
3) This is a big one: I find it is very difficult for users to develop custom meta boxes which include things such as data/time pickers. I feel it would be VERY VERY helpful to develop some type of example class for all different types of select/input meta box types. A key problem relates to how jquery or motools libraries are added without messing up other elements. In my example all I wanted to do is create an event calendar and found it very difficult to create the date/time calendar using motools as the date/time selections (to ensure fields are entered correctly).
—
Regarding your previous comments, would you potentially be willing to assist me on the development of such a media upload meta box if I could contribute some funds towards your developments? Please contact me by email when you have a moment.
Hi dimas.
I’have created a custom post type “A” with a custom meta “A-meta”.
I have a pb:
I want to display the list of all “A-meta” values but not especially in the specific custom” post type A page ” .
Here’s the error :Call to a member function the_meta() on a non-object in on line
It’s works good on ” post type A page ”
is their a way to do it.I’ve tryed with a function but it don’t work here.
I am not quite sure where you are trying to display the meta values?
Depending where you are trying to use the
$custom_metaboxobject (or similar) you might have to do:ok thanks!
it’s works with:
Thank you Dimas! It worked brilliantly.
first of all: super cool idea!
but i think i’ve found a bug: try your meta.php and check some checkboxes there, you’ll find that on relaod they are differently checked.
i’ve made a very simple example:
project-meta.php:
// $clients is ann array of another custom post-types... while($metabox->have_fields('clients', count($clients)) ): ?> get_the_index()]->post_title; ?> <input type="checkbox" name="the_name(); ?>" value="1" get_the_value()) echo 'checked="checked"'; ?> />let’s say i have 2 clients there, if you check the second and reload the admin-page, the first gets checked, not the second.
if you check both, both stay checked.
Micha, good catch … this gotcha stems from the internal
clean()function within the class (basically, cleaning and removing empty values).For example out of 3 check boxes if the last two are selected, the array would look like:
array('b','c')and NOT likearray(NULL,'b','c'). Because of this, there is not a one-to-one correlation with each of the check boxes in the loop.I will try to come up with some solution…
You can use the following, meanwhile:
<?php $clients = array('a','b','c'); ?> <?php $clients_selected = (array)$mb->get_the_value('clients'); ?> <?php while ($mb->have_fields('clients',count($clients))): ?> <?php $client = $clients[$mb->get_the_index()]; ?> <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $client; ?>"<?php if (in_array($client,$clients_selected)) echo ' checked="checked"'; ?>/><?php echo $client; ?><br/> <?php endwhile; ?>#1: I haven’t used custom taxonomies in a while, I played with them and I think I know where you are going with this suggestion. Similar to “links” in WordPress, it would be nice to be able to add an additional meta box to be able to extend its functionality (I don’t know if this is possible or not).
Possible Solution If this is NOT possible for taxonomies, a plugin can definitely be written as a helper to extend the data for taxonomies. It would have its own admin page (one location) where you could add extra data to each taxonomy.
#2: The storage selection in the case is NOT a new storage solution, in fact it still uses the default WordPress storage. By default the class will store a single value as an array, the “extract” mode will do the opposite (natively what WordPress does by default) which is to store each form field value as a single custom field entry.
This becomes useful when using functions like
query_posts()where you can interact with meta values. So if you are having problems with the speed and indexing of thewp_postmetatable, the modes this class introduces will not solve your issues.#3: Let me preface this by saying: I’ve seen meta box classes available which allows you to programatically create form fields, these classes work well, but fail when the developer needs to do something more custom. Personally I like to have as much control as possible when it comes to look, feel and functionality, essentially this is the reason that I went with a template based solution (role your own) vs programatic creation.
WordPress provides the
enqueue_script()function which work well for using third party solutions like jQuery and MooTools. I think what might be needed in this area is guidance, a tutorial to explain how to set some of this stuff up.$clients[$mb->get_the_index()]; ?>
that gives an ugly 500
get_the_index()]->post_title; ?>
which is sub-optimal too but at least it works for testing purposes …
ok i worked around that, but have found another small bug:
i’m currently fiddling around with multiple-fields in this case phone-numbers.
i copied the have_fields_and_multi() part and do have now:
have_fields_and_multi('phones')): ?>
the_group_open(); ?>
phone get_the_index()+1); ?>
<input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
get_the_index() > 0 ) : ?>
delete
the_group_close(); ?>
new phone
delete all
but after deleteing all phone-numbers the array count doesn’t get reset, i still have for example 4 as the_index.
it’s just a small glitch no big deal.
I was reading about how you can include specific meta boxes based on the category in which the post resides… However, my question is this:
Will the filters run on the meta box(es) as soon as the user clicks the checkbox for a particular category, or only after the user saves the post in that category?
Josh, currently it will update when the user clicks the update button, I will look into it, as having it immediately appear is definitely more intuitive.
Additionally give me your thoughts on the following: 1) I am thinking functionality, it might be that I have to have the meta box already present in the page (but hidden), when the use clicks the category then it gets displayed (not sure I really like this solution) … 2) also what if on click of the category a notice appeared, something like “new functionality present, please update post” …
thanks for your feedback!
Thanks, that’s kinda what I figured… I suppose I could just let the client know that they’ll need to click “Update/Publish” after choosing the appropriate category in order to see what sorts of custom options are available for that particular post.
I’m not sure I like the 1st idea either really… The less markup (visible or hidden), the better. (at least in my book)
As for your second idea, I really like that one. I know me personally, when I write a post in WordPress I don’t normally select the category and/or tags until AFTER I’ve already written the post, added the excerpt, given it a title, etc…
So if other people do the same, then it might be a very useful idea to display an alert letting them know that there are more options now available for them to fill out.
I just took a look at the “Select Category” section in the WordPress write page, and it looks like each of the checkboxes are given unique id’s like so: in-category-X where X = the category ID…
So I’d imagine it wouldn’t be too terribly hard to run a foreach loop and get all available category ID’s, then enqueue a JS file which has onclick events to run the filters.
Josh, thank you for your insights, I tend to operate similar to you, saving categories and tags for the end. I will work on a revision to this before the week is out (or this weekend).
This will also give me an opportunity to conceptualize and develop a way to give the developer access and to change the custom javascript and text messages that will be used within the class (most likely using wordpress’ filter and hooks functionality, possibly generic callback concepts, or maybe have developer extend the class).
I have an idea for a feature, but it might be a bit outside the scope of what you’re doing with the class.
Anyway, I think it’d be awesome if there were a shortcode available that could be inserted into the post editor which would then pull all values from a specific metabox and list them in the post itself.
See, I’m working on a site right now which does a lot of sports stats, and as it stands now I’m having to add the stats into tables for the guys who own the site because they know zilch about HTML.
So I thought it’d be awesome if I could create a “stats” metabox which would allow them to enter the name of the field like say “AVG”, and then the value of that field, like say “.398″.
They could fill the metabox with all sorts of stats, then by adding the shortcode into the post editor, it would then organize them all into a nice clean table.
Probably far outside the scope though.
Hi Dimas — For the past 6 hours i have been attempting to do various customizations to custom post types with the use of your meta box class. Bottom line is that your plugin in huge and I can see it being very useful for me.
I am running into a few issues which I just can’t seem to be able to solve and I hope you might be able to quickly help me out here.
1) One of the post_types I a creating is aimed at creating an event database. Everything here is going well except that I just can’t figure out exactly how to integrate a custom jquery script which allows for the selection of a date instead of having to enter it manually.
The code I am trying to integrate it this one:
http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/
I have attempted various integrations using the wp_enqueue_script element but things are just not showing up for me. Would you mind briefly trying to apply the mentioned jquery plugin to a form field and let me know what code you used in your functions file and meta.php file to enable it?
2) The second problem I was having related to creating a meta box for hobbies. What I was attempting to do is use your example code to essentially create just one meta and upon clicking the button, create a new blank form field. This is all working as expected and it essentially would allow me to have each hobby in its own form field. The problem I ran into was on the initial display as my goal was to provide an initial set of 5 blank form fields and if the editor needed more he would click the “add more” button which just add a single blank form field. How would I go about doing this?
3) Next problem I ran into was when I attempted to call a meta value from an entered form field using your script into the backend admin “post list” display. I am not sure if I am doing this correctly or not but after lots of hacking around I was finally able to get it to display using code like this:
add_action(‘manage_posts_custom_column’, ‘manage_events_columns’, 10, 2);
function manage_events_columns($column_name, $id) {
global $wpdb;
switch ($column_name) {
case ‘event_starts’:
global $custom_metabox_event_details;
$meta = $custom_metabox_event_details->the_meta();
echo $meta['event_location_address1'];
break;
case ‘event_types’:
$custom = get_post_custom();
echo get_the_term_list($post->ID, ‘event_types’, ”, ‘, ‘,”);
break;
default: break;
}
}
While the above code does work I am not sure if this is the correct way to call the value. Please let me know.
I was however not able to get a custom field value to show up when I used your class to create a custom field which can be duplicated. Please let me know how this should be done.
4) Here is a strange one which I am sure is a simple solution but I have been beating my head against the wall trying to get my meta.php file to including something as simple as get_post_thumbnail();
What is the correct method of being able to pull in information like this or for that matter any data or plugin which you would regularly be able to include with a public website template?
5) Finally, I have gone through your site and have managed to reposition the wysiwyg editor using your code but what I can’t figure out is how to essentially enable a regular form field dialog box with such a wysiwyg editor. The goal being to be able to use more than one dialog wysiwyg editor box. Please let me know how we can achieve this.
Thank you VERY much for your help in advance.
Eu estou usando assim:
get_template_part( ‘lib/WPAlchemy/MetaBox’, ‘index’ );
porque se tiver em meu template, ele vai carregar, e se tiver no meu tema, ele também irá carregar; nesta ordem.
Hello!
I’m using MAMP to develop and test my wordpress theme but for some reason whenever I add the metaBoxes to the functions.php I’m faced with a blank page when I test the results. It’s fine when I’m using it ‘live’, I just have dramas in MAMP!!!!
Louisa
+1 on #5 . How to add WYSIWYG to meta box, and/or HTML/Visual mode toggle.
Josh, I too think this would be a great feature. Have you had any luck coming up with a workaround?
Chris, I apologize for not getting back to you sooner, I’ve got an answer for #1:
This is how i set everything up:
functions.phpdefine('_TEMPLATEURL',WP_CONTENT_URL.'/themes/'.basename(TEMPLATEPATH)); if (is_admin()) { wp_enqueue_script('custom_js_jquery_ui',_TEMPLATEURL .'/custom/js/jquery-ui-1.7.1.custom.min.js',array('jquery')); wp_enqueue_script('custom_js_daterangepicker',_TEMPLATEURL .'/custom/js/daterangepicker.jQuery.js',array('jquery')); wp_enqueue_script('custom_js_custom',_TEMPLATEURL .'/custom/js/custom.js',array('jquery'),NULL,TRUE); wp_enqueue_style('custom_css_daterangepicker',_TEMPLATEURL .'/custom/css/ui.daterangepicker.css'); wp_enqueue_style('custom_css_jquery_ui',_TEMPLATEURL .'/custom/css/redmond/jquery-ui-1.7.1.custom.css'); }meta.phpcustom.js(custom js file I use to add all my custom js)jQuery(function($) { $('#rangeA').daterangepicker({arrows:true}); });The above was not working for me at first, the key is to avoid using “$” in the global space, I believe WordPress uses the
jQuery.noConflict()option.With that said, the above works, but the below will NOT:
$(function() { $('#rangeA').daterangepicker({arrows:true}); });#2 consider using
have_fields_and_multi($name), in the initial download I have a good working example. There is also a function calledhave_fields_and_one()(which is depreciated), it always adds an extra field at the end (after each update).I have to go for now, but will follow up with you on your other questions this weekend.
Louisa, make sure you you have error reporting ON in your local environment.
You can make INI adjustments or try using the following inline in your code:
error_reporting(E_ALL); ini_set("display_errors", 1);Scott, no I’ve not been able to work up a solution/workaround just yet… I’m still trying to get the project finished, so I haven’t had time to try and find a way to accomplish this…
It was just an idea I had while adding other metaboxes for static info, so I thought I’d post it here to get Dimas’ thoughts on the idea.
I do think it may be outside the scope of the class, but your idea has got me thinking of a debug method for printing out all the values of a metabox.
Hey Dimas… I don’t want to sound like a complete idiot, but it seems i’ve somehow managed to create an infinite loop using your class and the “multi” option.
I’m adding a metabox which will allow the owners to add “Email Groups” to their sidebar. Each “Group” would contain multiple email addresses, which the owner could add by clicking one of the buttons. Each email address is 2 fields: 1 for email, 1 for name of owner…
However, as I said, it’s somehow creating an infinite loop that just killed my server.
haha
Here’s my code, can you see if you can tell what the heck I did wrong?
<h6>Email Addresses and Groups</h6> <a style="float:right; margin:0 10px;" href="#" class="dodelete-email-group button">Remove All</a> <p>Here you can not only add email addresses you'd like to be visible to the public, but you can also group them by department and give them their own headings as well. Simply click the "Add Email Group" button to create a new grouping of email addresses. Afterwhich, you can add new email addresses to that group by clicking the "Add Email" button.</p> <?php while($mb->have_fields_and_multi('email-group')): ?> <?php $mb->the_group_open(); ?> <?php $mb->the_field('group-title'); ?> <label>Email Group Title</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <?php $mb->the_field('email'); ?> <label>Email Address</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <?php $mb->the_field('owner'); ?> <label>Name of Owner</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <p><a href="#" class="dodelete button">Remove Email</a></p> <p><a href="#" class="docopy-email-address button">Add Email</a></p> <?php $mb->the_group_close(); ?> <?php endwhile; ?> <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-email-group button">Add Email Group</a></p>Sorry, disregard the code I posted above… That’s after I already removed one of the loops so I could stop the server from dying.
Here’s the invalid code that creates an infinite loop… I know which section creates the infinite loop, I just don’t know why it doesn’t work as I had expected.
<h6>Email Addresses and Groups</h6> <a style="float:right; margin:0 10px;" href="#" class="dodelete-email-group button">Remove All</a> <p>Here you can not only add email addresses you'd like to be visible to the public, but you can also group them by department and give them their own headings as well. Simply click the "Add Email Group" button to create a new grouping of email addresses. Afterwhich, you can add new email addresses to that group by clicking the "Add Email" button.</p> <?php while($mb->have_fields_and_multi('email-group')): ?> <?php $mb->the_group_open(); ?> <?php $mb->the_field('group-title'); ?> <label>Email Group Title</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <?php while($mb->have_fields_and_multi('email-address')): ?> <?php $mb->the_group_open(); ?> <?php $mb->the_field('email'); ?> <label>Email Address</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <?php $mb->the_field('owner'); ?> <label>Name of Owner</label> <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p> <p><a href="#" class="dodelete button">Remove Email</a></p> <?php $mb->the_group_close(); ?> <?php endwhile; ?> <p><a href="#" class="docopy-email-address button">Add Email</a></p> <?php $mb->the_group_close(); ?> <?php endwhile; ?> <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-email-group button">Add Email Group</a></p>Josh, a current unfortunate short coming of the Meta Box class is that it only tracks a single level when using any of the loop functions … so having an inner loop is currently not possible.
However, the Meta Box loop functions basically are used to write proper form field names and get values … these tasks can be done manually using regular PHP loops and functions … you may not be able to use all of the classes helper functions when doing things manually.
You’ve displayed a very good working example of the need for inner loops. I’ve added it to the list. I will try to make it possible to track unlimited amount of loops, but if that becomes too complex I may scale down up to 3 levels.
Ok, I was afraid I had actually done something stupid which caused it.
Do you happen to have any ideas how I could still achieve the same effect manually?
I just want to be able to let them add “Email Groups” by clicking a button, and each of those groups would contain multiple “Email Addresses” which they could add by clicking a button as well…
Think it’s gonna be too complex?
Josh, it will be a little complex, if you decide to move forward, this should help get you started:
Your form field names will need to look similar to this (you’ll have to use your own PHP to generate these names using your own PHP loop):
The Meta Box class will still assist you with it’s built in javascript for duplicating the fields. You will have to setup your HTML as such:
Note: you will need to generate a blank group (hidden) at the end of a group loop, also the .tocopy class needs to be on the last instance of the generated group.
On line #443 in
MetaBox.phpyou will have to change:var the_match = the_name.match(/\[(\d+)\]/i); the_name = the_name.replace(the_match[0],'['+(+the_match[1]+1)+']'); $(elem).attr('name',the_name);to…
the_name = the_name.split("").reverse().join(""); var the_match = the_name.match(/\](\d+)\[/i); the_name = the_name.replace(the_match[0],']'+(+the_match[1]+1)+'['); the_name = the_name.split("").reverse().join(""); $(elem).attr('name',the_name);Also, I think you may have some troubles with inner loop duplication, so you will probably have to do some additional modifications to the javascript in the MetaBox.php file line #427 to #457 … i’ll revise the code also when I have some additional time … todo: this code needs to be revised so that when a button is pressed “add” it is context sensitive (delete button) works like this already, “add” should check which group its in, look for the .tocopy class and duplicate it…
This should get you started…
Ping me via email and we can talk further about this…
Wow, that does seem like it’s going to be pretty complex! haha
I think I’ll just hardcode it for now into the theme’s contact page, and then maybe later if you add the functionality to the class, then I may go back and revise it.
Thanks Dimas!!!!
Hi Dimas,
Firstly, great work with the Metabox Class.
I created a metabox textarea thats going with a post and I am trying to run shortcode in but does not seem to be rendering, its just spitting out the raw shortcode tag.
I was wondering if you allowed for shortcode to be processed in the metaboxes and if not, what needs to be added to make it possible for shortcodes to work
Another question I have is how would you include a metabox outside the loop, I am currently doing it like so and want to make sure its fine.
Thanks & Regards
Said
Said, in terms of processing shortcodes, the Meta Box class will not do that for you, you will have to call
do_shortcode($content)on the content you want processed for shortcodes.In the loop or outside of the loop you can do what you are doing or you can do the following:
$custom_metabox->the_meta(); $custom_metabox->get_value('_column_one');Hi Dimas,
your wpalchemy plugin is very useful. Since I started using it, wordpress administration is much easier for the clients. Thanks for that.
Since making custom metabox-es is very useful, I was thinking what else would we need to have a better and easier wordpress administration. In my opinion, it would be nice to have an easy way to create a theme options page. Here we could store some general setting that are not related to each post/page like metaboxes.
What do you think, is this a good candidate for a class/plugin similar to WPAlchemy ? I am a designer so I can’t do this myself, but I wanted to share this idea with you.
Thanks
Hi Dimas — Thank you very much for your response in regards to the date range picker.
I have followed your instructions exactly as mentioned and have tested various different ways and things that might be the issue including disabling other plugins all without luck though…. it just won’t show up. Everything loads fine but when I go to click on the box which should pull up the date picker nothing happens.
I have verified that the page is indeed calling the correct scripts (which are being included) and I have even integrated it without any modification to the point where I just had the one box show up… still nothing tough.
Could you maybe review this once again to ensure there are no difference in your working code?
Also, do you happen to know how I can change the functions.php file code you included above so that it would only load the applicable code on the actual custom post type of events and nowhere else? I think this is important to avoid possible other conflicts with other plugins and just cleaner to ensure extra stuff is not being loaded.
Also, I would greatly appreciate if you might be able to review the other points/questions stated in the above comment and hopefully elaborate a point #2 that you began to address above. Thanks you very much in advance!
Horia, I very much appreciate your comments and hope that you will continue to use WPAlchemy as it grows. Similar to your thoughts, I want WPAlchemy to be a lightweight helper framework on top of WordPress. The key goal being: to help designers/developers setup custom admin UIs with minimal effort. I’ve got two development threads going on right now in regards to WPAlchemy … 1) a plugin creation/helper class to help plugin developers create and standardize plugins … 2) a class to assist custom admin menu creation … once I have these to a good working state I will release a preview release.
#1 try doing it on a fresh wordpress install…
#2 I’ve made a revision to the WPAlchemy MetaBox class which should help you out, grab the latest development release … if you are already using
have_fields_and_multi()you can simply add a length parameter to it:$mb->have_fields_and_multi('docs',5)#3 Your code looks good … if you want to use the class methods you can do the following:
global $custom_metabox_event_details; $custom_metabox_event_details->the_meta(); // this will echo the value $custom_metabox_event_details->the_value('event_location_address1'); // this will get the value $address = $custom_metabox_event_details->get_the_value('event_location_address1');To loop through duplicated fields see the template example above.
Note: the
$metais a raw dump of the meta values, to see how things are stored do:print_r($meta);.#4 try:
see the codex for more info.
Note: when a meta box template is included, it is included inside a function, this means that global variables are not available and you must explicitly use
global $VARIABLEto use a global variable. As a convenience, the class will auto callglobal $postmaking the$postvar available.#5 I haven’t had a need for this yet, however I have tried to play around with it a while back, WordPress has filters for tapping into TinyMCE (you might be able to use those). I would recommend that you try to find a plugin which adds multiple TinyMCE boxes and either use the plugin OR look at the plugin code to see how it is being done.
cool — this “$mb->have_fields_and_multi(‘docs’,5)” works exactly as I was hoping it would which is great.
Now, if there is just some way (when you get a free moment of course) to confirm with me the correct inclusion of that jquery date picker so gets correctly loaded for only a specific custom post type then I think I finally can get this custom metabox done.
BTW – I looked at echo get_the_post_thumbnail($post->ID); and that did work… I did not know it understand the $post query. I hope this now lets me include other data in here correctly to get this metabox in place.
Looking forward to your response!
Dimas,
First off, your WPAlchemy Meta Box class is great! It is by far the best code I’ve come across when dealing with custom meta boxes. With that said, I have a couple questions that I was hoping you could help me out on (I skimmed the comments above, so hopefully you haven’t touched on either of these subjects)
1. I have integrated the “Add” button with the group feature and I was wondering if there was any way to set a limit to the number of instances created. (I want individuals to add a max of 3 additional instances)
2. I am using the UI Datepicker function in my admin and it works for the initial instance, but once I press the Add button the Datepicker neglects to pop up. The class must not be carrying down to the next instance for that is what initiates the Datepicker function. (Note: if i add a second instance and “Update” it, the Datepicker will work)
Thanks so much and any guidance is greatly appreciated!
Tyler
Tyler, I like your idea for #1 very much, I will definitely implement this.
As for #2, this is what I think is happening: the first element gets initiated with the date picker, but because the next element is dynamically duplicated it does not get initiated. This is currently a shortcoming which I will also address in the next release. What you can do meanwhile is edit, the javascript portion of the code and when the element gets cloned, you can initialize the cloned date picker at that time.
Tyler, about your #2 problem, if I understood correctly, the Datepicker is not showing for the elements added dynamically because they are added after the .bind() or .click() call.
If that is the case you could try to use the .live() jquery function to set the click events.
$(‘.clickme’).live(‘click’, function() {
// Live handler called.
});
Hope it helps.
Dimas,
Thanks for the quick response. I have one more inquiry that I’m sure you could help me out with. When I use the group function with the “Add” button is it possible to grab a particular value out of that grouped array. If this were possible it seems like you’d do something like $meta['docs'][0]['title'], but this doesn’t work. Once again thanks a lot!
Tyler
Hi
I keep getting this error message:
Fatal error: Call to a member function the_meta() on a non-object in /nfs/c01/h06/mnt/13626……
Whilst using this code in my template:
the_meta();
echo $meta['name'];
echo $meta['age'];
?>
Here is the page: http://frozengrape.co.uk/184/test/
Could any tell me what is wrong with my template code?
Many thanks
Ben
Horia,
Thanks for the reply. I tried implementing your technique and it didn’t seem to work. I appreciate the help though!
Tyler
Ben, see the Using The Meta Box Values In Your Template section of the documentation. You basically want to do something like this:
global $custom_metabox; // depending on where you use $custom_metabox you may need this $custom_metabox->the_meta(); $custom_metabox->the_value('name'); $custom_metabox->the_value('age');Depending on where you are using
$custom_metabox, you may need to useglobal.Hi Dimas — First of all… I got almost everything working over here based on your suggestions so thank you very much!
I did run into two additional issues though which I am having difficultly with both still relate to this event calendar.
A) on the public website templates what I am trying to do here is essentially run a wordpress query on this event post type and now I want to sort these posts by a specific meta value. What I seem t have noticed is that I can’t just use the standard meta key which was assigned to the custom field I created for “event_start_date”. As such… how are we supposed to define that applicable meta key field within the post query string?
Here is what I am using:
query_posts(‘post_type=events&meta_key=event_start_date&orderby=meta_value&posts_per_page=-1&order=ASC’);
B) I finally did end up getting the jquery meta box to show up (it was actually a stupid problem on my end)… what I however seem to be unable to achieve is making this custom event post type allow for more than one event to be inserted.
More specifically, I created three custom fields:
* event_start_date
* event_start_time
* event_end_time
I have “event_start_date” associated with the jquery datepicker which is working fine.
Now I want to create a “add new” button to essentially how the editor to enter all the applicable dates and the from-to times a specific event will be taking place.
As mentioned in a different post by someone this is creating problems. Would you mind reviewing this please and possibly providing the correct code so that such groups can be duplicated?
C) Assuming the above would not work… the very inconvenient way the editor would have to go about things would be to create a new post for every single event individually. While I guess this would be better than nothing (as mentioned above) what I am really trying to achieve here is allowing that editor to create one “event” and then just add the applicable dates and times that event will take place.
The problem with this situation is that I don’t have any clue based on your code on how I would run a query_posts command which NOT ONLY spits out every single event post but essentially “for each” event post it would need to extract/print all the applicable event dates/times and then sort all of the results by one of the meta key values.
Something tell me that you have already though about this and have this built in but I am confused on how to actually do this… Can you provide some help here?
D) I believe I did find an issue with the recent code modification you made related to: $mb->have_fields_and_multi(‘docs’,5)
What I noticed is that if (as mentioned above) you set a value of 5 lines to print, then fill out each of these 5, then go ahead and click the “add” meta box and enter a 6 entry, then save… when the page refreshes and/or when you access it again later there will only be 5 entries and the 6th one can’t be seen or modified.
As usual, I think you in advance for your assistance!
Chris, for A take a look at this and see if it resolves your issues. Additionally for D I have a development release which solves this issue.
Hi Dimas — Boy, I have having some troubles just getting these posts to display and order themselfs corrctly.
I look at the code suggestion which it seems its not working as I am always getting a blank page.
I have included the code I have used for all elements below. Please do take a look to see if you notice anything I might be doing wrong.
First of all – from you last comments here is what I have done to query the posts based off the meta .
query_posts('post_type=events&posts_per_page=-1&order=ASC&orderby=meta_value&meta_key=' . $custom_metabox_event_dates->get_the_name('event_start_date'));Here is the full code I am using for the public website template were I am listing all of the events and attempting to have them sorted by date:
the_meta(); $meta2 = $custom_metabox_event_details->the_meta(); ?> "01", "02" => "02", "03" => "03", "04" => "04", "05" => "05", "06" => "06", "07" => "07", "08" => "08", "09" => "09", "10" => "10", "11" => "11", "12" => "12"); $arrMonthNames = array("01" => "JANUARY", "02" => "FEBRUARY", "03" => "MARCH", "04" => "APRIL", "05" => "MAY", "06" => "JUNE", "07" => "JULY", "08" => "AUGUST", "09" => "SEPTEMBER", "10" => "OCTOBER", "11" => "NOVEMBER", "12" => "DECEMBER"); query_posts('post_type=events&posts_per_page=-1&order=ASC&orderby=meta_value&meta_key=' . $custom_metabox_event_dates->get_the_name('event_start_date')); ?> = $today) { ?> <?php $show_month = date('m', $show_date); if ($arrMonthNums[$show_month] == $show_month) { echo "EVENTS IN ".$arrMonthNames[$show_month].""; $arrMonthNums[$show_month] = "printed"; } if($show_date == $today) { ?> - <a href=""> EVENT TYPE: ID, 'event_types', '', ', ',''); ?> LOCATION:Here is the code I am using for the “event_dates” metabox
Start Date the_field('event_start_date'); ?> <input autocomplete="off" id="rangeA" type="text" name="the_name(); ?>" value="the_value(); ?>"/> Start Time the_field('event_start_time'); ?> <select name="the_name(); ?>"> Select Time <option value="6:00 AM" is_value('6:00 AM')?' selected="selected"':''; ?>/>6:00 AM <option value="6:15 AM" is_value('6:15 AM')?' selected="selected"':''; ?>/>6:15 AM <option value="6:30 AM" is_value('6:30 AM')?' selected="selected"':''; ?>/>6:30 AM <option value="6:45 AM" is_value('6:45 AM')?' selected="selected"':''; ?>/>6:45 AM <option value="7:00 AM" is_value('7:00 AM')?' selected="selected"':''; ?>/>7:00 AM <option value="7:15 AM" is_value('7:15 AM')?' selected="selected"':''; ?>/>7:15 AM <option value="7:30 AM" is_value('7:30 AM')?' selected="selected"':''; ?>/>7:30 AM <option value="7:45 AM" is_value('7:45 AM')?' selected="selected"':''; ?>/>7:45 AM <option value="8:00 AM" is_value('8:00 AM')?' selected="selected"':''; ?>/>8:00 AM <option value="8:15 AM" is_value('8:15 AM')?' selected="selected"':''; ?>/>8:15 AM <option value="8:30 AM" is_value('8:30 AM')?' selected="selected"':''; ?>/>8:30 AM <option value="8:45 AM" is_value('8:45 AM')?' selected="selected"':''; ?>/>8:45 AM <option value="9:00 AM" is_value('9:00 AM')?' selected="selected"':''; ?>/>9:00 AM <option value="9:15 AM" is_value('9:15 AM')?' selected="selected"':''; ?>/>9:15 AM <option value="9:30 AM" is_value('9:30 AM')?' selected="selected"':''; ?>/>9:30 AM <option value="9:45 AM" is_value('9:45 AM')?' selected="selected"':''; ?>/>9:45 AM <option value="10:00 AM" is_value('10:00 AM')?' selected="selected"':''; ?>/>10:00 AM <option value="10:15 AM" is_value('10:15 AM')?' selected="selected"':''; ?>/>10:15 AM <option value="10:30 AM" is_value('10:30 AM')?' selected="selected"':''; ?>/>10:30 AM <option value="10:45 AM" is_value('10:45 AM')?' selected="selected"':''; ?>/>10:45 AM <option value="11:00 AM" is_value('11:00 AM')?' selected="selected"':''; ?>/>11:00 AM <option value="11:15 AM" is_value('11:15 AM')?' selected="selected"':''; ?>/>11:15 AM <option value="11:30 AM" is_value('11:30 AM')?' selected="selected"':''; ?>/>11:30 AM <option value="11:45 AM" is_value('11:45 AM')?' selected="selected"':''; ?>/>11:45 AM <option value="12:00 PM" is_value('12:00 PM')?' selected="selected"':''; ?>/>12:00 PM <option value="12:15 PM" is_value('12:15 PM')?' selected="selected"':''; ?>/>12:15 PM <option value="12:30 PM" is_value('12:30 PM')?' selected="selected"':''; ?>/>12:30 PM <option value="12:45 PM" is_value('12:45 PM')?' selected="selected"':''; ?>/>12:45 PM <option value="1:00 PM" is_value('1:00 PM')?' selected="selected"':''; ?>/>1:00 PM <option value="1:15 PM" is_value('1:15 PM')?' selected="selected"':''; ?>/>1:15 PM <option value="1:30 PM" is_value('1:30 PM')?' selected="selected"':''; ?>/>1:30 PM <option value="1:45 PM" is_value('1:45 PM')?' selected="selected"':''; ?>/>1:45 PM <option value="2:00 PM" is_value('2:00 PM')?' selected="selected"':''; ?>/>2:00 PM <option value="2:15 PM" is_value('2:15 PM')?' selected="selected"':''; ?>/>2:15 PM <option value="2:30 PM" is_value('2:30 PM')?' selected="selected"':''; ?>/>2:30 PM <option value="2:45 PM" is_value('2:45 PM')?' selected="selected"':''; ?>/>2:45 PM <option value="3:00 PM" is_value('3:00 PM')?' selected="selected"':''; ?>/>3:00 PM <option value="3:15 PM" is_value('3:15 PM')?' selected="selected"':''; ?>/>3:15 PM <option value="3:30 PM" is_value('3:30 PM')?' selected="selected"':''; ?>/>3:30 PM <option value="3:45 PM" is_value('3:45 PM')?' selected="selected"':''; ?>/>3:45 PM <option value="4:00 PM" is_value('4:00 PM')?' selected="selected"':''; ?>/>4:00 PM <option value="4:15 PM" is_value('4:15 PM')?' selected="selected"':''; ?>/>4:15 PM <option value="4:30 PM" is_value('4:30 PM')?' selected="selected"':''; ?>/>4:30 PM <option value="4:45 PM" is_value('4:45 PM')?' selected="selected"':''; ?>/>4:45 PM <option value="5:00 PM" is_value('5:00 PM')?' selected="selected"':''; ?>/>5:00 PM <option value="5:15 PM" is_value('5:15 PM')?' selected="selected"':''; ?>/>5:15 PM <option value="5:30 PM" is_value('5:30 PM')?' selected="selected"':''; ?>/>5:30 PM <option value="5:45 PM" is_value('5:45 PM')?' selected="selected"':''; ?>/>5:45 PM <option value="6:00 PM" is_value('6:00 PM')?' selected="selected"':''; ?>/>6:00 PM <option value="6:15 PM" is_value('6:15 PM')?' selected="selected"':''; ?>/>6:15 PM <option value="6:30 PM" is_value('6:30 PM')?' selected="selected"':''; ?>/>6:30 PM <option value="6:45 PM" is_value('6:45 PM')?' selected="selected"':''; ?>/>6:45 PM <option value="7:00 PM" is_value('7:00 PM')?' selected="selected"':''; ?>/>7:00 PM <option value="7:15 PM" is_value('7:15 PM')?' selected="selected"':''; ?>/>7:15 PM <option value="7:30 PM" is_value('7:30 PM')?' selected="selected"':''; ?>/>7:30 PM <option value="7:45 PM" is_value('7:45 PM')?' selected="selected"':''; ?>/>7:45 PM <option value="8:00 PM" is_value('8:00 PM')?' selected="selected"':''; ?>/>8:00 PM <option value="8:15 PM" is_value('8:15 PM')?' selected="selected"':''; ?>/>8:15 PM <option value="8:30 PM" is_value('8:30 PM')?' selected="selected"':''; ?>/>8:30 PM <option value="8:45 PM" is_value('8:45 PM')?' selected="selected"':''; ?>/>8:45 PM <option value="9:00 PM" is_value('9:00 PM')?' selected="selected"':''; ?>/>9:00 PM <option value="9:15 PM" is_value('9:15 PM')?' selected="selected"':''; ?>/>9:15 PM <option value="9:30 PM" is_value('9:30 PM')?' selected="selected"':''; ?>/>9:30 PM <option value="9:45 PM" is_value('9:45 PM')?' selected="selected"':''; ?>/>9:45 PM <option value="10:00 PM" is_value('10:00 PM')?' selected="selected"':''; ?>/>10:00 PM <option value="10:15 PM" is_value('10:15 PM')?' selected="selected"':''; ?>/>10:15 PM <option value="10:30 PM" is_value('10:30 PM')?' selected="selected"':''; ?>/>10:30 PM <option value="10:45 PM" is_value('10:45 PM')?' selected="selected"':''; ?>/>10:45 PM <option value="11:00 PM" is_value('11:00 PM')?' selected="selected"':''; ?>/>11:00 PM <option value="11:15 PM" is_value('11:15 PM')?' selected="selected"':''; ?>/>11:15 PM <option value="11:30 PM" is_value('11:30 PM')?' selected="selected"':''; ?>/>11:30 PM <option value="11:45 PM" is_value('11:45 PM')?' selected="selected"':''; ?>/>11:45 PM <option value="12:00 AM" is_value('12:00 AM')?' selected="selected"':''; ?>/>12:00 AM <option value="12:15 AM" is_value('12:15 AM')?' selected="selected"':''; ?>/>12:15 AM <option value="12:30 AM" is_value('12:30 AM')?' selected="selected"':''; ?>/>12:30 AM <option value="12:45 AM" is_value('12:45 AM')?' selected="selected"':''; ?>/>12:45 AM <option value="1:00 AM" is_value('1:00 AM')?' selected="selected"':''; ?>/>1:00 AM <option value="1:15 AM" is_value('1:15 AM')?' selected="selected"':''; ?>/>1:15 AM <option value="1:30 AM" is_value('1:30 AM')?' selected="selected"':''; ?>/>1:30 AM <option value="1:45 AM" is_value('1:45 AM')?' selected="selected"':''; ?>/>1:45 AM <option value="2:00 AM" is_value('2:00 AM')?' selected="selected"':''; ?>/>2:00 AM <option value="2:15 AM" is_value('2:15 AM')?' selected="selected"':''; ?>/>2:15 AM <option value="2:30 AM" is_value('2:30 AM')?' selected="selected"':''; ?>/>2:30 AM <option value="2:45 AM" is_value('2:45 AM')?' selected="selected"':''; ?>/>2:45 AM <option value="3:00 AM" is_value('3:00 AM')?' selected="selected"':''; ?>/>3:00 AM <option value="3:15 AM" is_value('3:15 AM')?' selected="selected"':''; ?>/>3:15 AM <option value="3:30 AM" is_value('3:30 AM')?' selected="selected"':''; ?>/>3:30 AM <option value="3:45 AM" is_value('3:45 AM')?' selected="selected"':''; ?>/>3:45 AM <option value="4:00 AM" is_value('4:00 AM')?' selected="selected"':''; ?>/>4:00 AM <option value="4:15 AM" is_value('4:15 AM')?' selected="selected"':''; ?>/>4:15 AM <option value="4:30 AM" is_value('4:30 AM')?' selected="selected"':''; ?>/>4:30 AM <option value="4:45 AM" is_value('4:45 AM')?' selected="selected"':''; ?>/>4:45 AM <option value="5:00 AM" is_value('5:00 AM')?' selected="selected"':''; ?>/>5:00 AM <option value="5:15 AM" is_value('5:15 AM')?' selected="selected"':''; ?>/>5:15 AM <option value="5:30 AM" is_value('5:30 AM')?' selected="selected"':''; ?>/>5:30 AM <option value="5:45 AM" is_value('5:45 AM')?' selected="selected"':''; ?>/>5:45 AM End Time the_field('event_end_time'); ?> <select name="the_name(); ?>"> Select Time <option value="6:00 AM" is_value('6:00 AM')?' selected="selected"':''; ?>/>6:00 AM <option value="6:15 AM" is_value('6:15 AM')?' selected="selected"':''; ?>/>6:15 AM <option value="6:30 AM" is_value('6:30 AM')?' selected="selected"':''; ?>/>6:30 AM <option value="6:45 AM" is_value('6:45 AM')?' selected="selected"':''; ?>/>6:45 AM <option value="7:00 AM" is_value('7:00 AM')?' selected="selected"':''; ?>/>7:00 AM <option value="7:15 AM" is_value('7:15 AM')?' selected="selected"':''; ?>/>7:15 AM <option value="7:30 AM" is_value('7:30 AM')?' selected="selected"':''; ?>/>7:30 AM <option value="7:45 AM" is_value('7:45 AM')?' selected="selected"':''; ?>/>7:45 AM <option value="8:00 AM" is_value('8:00 AM')?' selected="selected"':''; ?>/>8:00 AM <option value="8:15 AM" is_value('8:15 AM')?' selected="selected"':''; ?>/>8:15 AM <option value="8:30 AM" is_value('8:30 AM')?' selected="selected"':''; ?>/>8:30 AM <option value="8:45 AM" is_value('8:45 AM')?' selected="selected"':''; ?>/>8:45 AM <option value="9:00 AM" is_value('9:00 AM')?' selected="selected"':''; ?>/>9:00 AM <option value="9:15 AM" is_value('9:15 AM')?' selected="selected"':''; ?>/>9:15 AM <option value="9:30 AM" is_value('9:30 AM')?' selected="selected"':''; ?>/>9:30 AM <option value="9:45 AM" is_value('9:45 AM')?' selected="selected"':''; ?>/>9:45 AM <option value="10:00 AM" is_value('10:00 AM')?' selected="selected"':''; ?>/>10:00 AM <option value="10:15 AM" is_value('10:15 AM')?' selected="selected"':''; ?>/>10:15 AM <option value="10:30 AM" is_value('10:30 AM')?' selected="selected"':''; ?>/>10:30 AM <option value="10:45 AM" is_value('10:45 AM')?' selected="selected"':''; ?>/>10:45 AM <option value="11:00 AM" is_value('11:00 AM')?' selected="selected"':''; ?>/>11:00 AM <option value="11:15 AM" is_value('11:15 AM')?' selected="selected"':''; ?>/>11:15 AM <option value="11:30 AM" is_value('11:30 AM')?' selected="selected"':''; ?>/>11:30 AM <option value="11:45 AM" is_value('11:45 AM')?' selected="selected"':''; ?>/>11:45 AM <option value="12:00 PM" is_value('12:00 PM')?' selected="selected"':''; ?>/>12:00 PM <option value="12:15 PM" is_value('12:15 PM')?' selected="selected"':''; ?>/>12:15 PM <option value="12:30 PM" is_value('12:30 PM')?' selected="selected"':''; ?>/>12:30 PM <option value="12:45 PM" is_value('12:45 PM')?' selected="selected"':''; ?>/>12:45 PM <option value="1:00 PM" is_value('1:00 PM')?' selected="selected"':''; ?>/>1:00 PM <option value="1:15 PM" is_value('1:15 PM')?' selected="selected"':''; ?>/>1:15 PM <option value="1:30 PM" is_value('1:30 PM')?' selected="selected"':''; ?>/>1:30 PM <option value="1:45 PM" is_value('1:45 PM')?' selected="selected"':''; ?>/>1:45 PM <option value="2:00 PM" is_value('2:00 PM')?' selected="selected"':''; ?>/>2:00 PM <option value="2:15 PM" is_value('2:15 PM')?' selected="selected"':''; ?>/>2:15 PM <option value="2:30 PM" is_value('2:30 PM')?' selected="selected"':''; ?>/>2:30 PM <option value="2:45 PM" is_value('2:45 PM')?' selected="selected"':''; ?>/>2:45 PM <option value="3:00 PM" is_value('3:00 PM')?' selected="selected"':''; ?>/>3:00 PM <option value="3:15 PM" is_value('3:15 PM')?' selected="selected"':''; ?>/>3:15 PM <option value="3:30 PM" is_value('3:30 PM')?' selected="selected"':''; ?>/>3:30 PM <option value="3:45 PM" is_value('3:45 PM')?' selected="selected"':''; ?>/>3:45 PM <option value="4:00 PM" is_value('4:00 PM')?' selected="selected"':''; ?>/>4:00 PM <option value="4:15 PM" is_value('4:15 PM')?' selected="selected"':''; ?>/>4:15 PM <option value="4:30 PM" is_value('4:30 PM')?' selected="selected"':''; ?>/>4:30 PM <option value="4:45 PM" is_value('4:45 PM')?' selected="selected"':''; ?>/>4:45 PM <option value="5:00 PM" is_value('5:00 PM')?' selected="selected"':''; ?>/>5:00 PM <option value="5:15 PM" is_value('5:15 PM')?' selected="selected"':''; ?>/>5:15 PM <option value="5:30 PM" is_value('5:30 PM')?' selected="selected"':''; ?>/>5:30 PM <option value="5:45 PM" is_value('5:45 PM')?' selected="selected"':''; ?>/>5:45 PM <option value="6:00 PM" is_value('6:00 PM')?' selected="selected"':''; ?>/>6:00 PM <option value="6:15 PM" is_value('6:15 PM')?' selected="selected"':''; ?>/>6:15 PM <option value="6:30 PM" is_value('6:30 PM')?' selected="selected"':''; ?>/>6:30 PM <option value="6:45 PM" is_value('6:45 PM')?' selected="selected"':''; ?>/>6:45 PM <option value="7:00 PM" is_value('7:00 PM')?' selected="selected"':''; ?>/>7:00 PM <option value="7:15 PM" is_value('7:15 PM')?' selected="selected"':''; ?>/>7:15 PM <option value="7:30 PM" is_value('7:30 PM')?' selected="selected"':''; ?>/>7:30 PM <option value="7:45 PM" is_value('7:45 PM')?' selected="selected"':''; ?>/>7:45 PM <option value="8:00 PM" is_value('8:00 PM')?' selected="selected"':''; ?>/>8:00 PM <option value="8:15 PM" is_value('8:15 PM')?' selected="selected"':''; ?>/>8:15 PM <option value="8:30 PM" is_value('8:30 PM')?' selected="selected"':''; ?>/>8:30 PM <option value="8:45 PM" is_value('8:45 PM')?' selected="selected"':''; ?>/>8:45 PM <option value="9:00 PM" is_value('9:00 PM')?' selected="selected"':''; ?>/>9:00 PM <option value="9:15 PM" is_value('9:15 PM')?' selected="selected"':''; ?>/>9:15 PM <option value="9:30 PM" is_value('9:30 PM')?' selected="selected"':''; ?>/>9:30 PM <option value="9:45 PM" is_value('9:45 PM')?' selected="selected"':''; ?>/>9:45 PM <option value="10:00 PM" is_value('10:00 PM')?' selected="selected"':''; ?>/>10:00 PM <option value="10:15 PM" is_value('10:15 PM')?' selected="selected"':''; ?>/>10:15 PM <option value="10:30 PM" is_value('10:30 PM')?' selected="selected"':''; ?>/>10:30 PM <option value="10:45 PM" is_value('10:45 PM')?' selected="selected"':''; ?>/>10:45 PM <option value="11:00 PM" is_value('11:00 PM')?' selected="selected"':''; ?>/>11:00 PM <option value="11:15 PM" is_value('11:15 PM')?' selected="selected"':''; ?>/>11:15 PM <option value="11:30 PM" is_value('11:30 PM')?' selected="selected"':''; ?>/>11:30 PM <option value="11:45 PM" is_value('11:45 PM')?' selected="selected"':''; ?>/>11:45 PM <option value="12:00 AM" is_value('12:00 AM')?' selected="selected"':''; ?>/>12:00 AM <option value="12:15 AM" is_value('12:15 AM')?' selected="selected"':''; ?>/>12:15 AM <option value="12:30 AM" is_value('12:30 AM')?' selected="selected"':''; ?>/>12:30 AM <option value="12:45 AM" is_value('12:45 AM')?' selected="selected"':''; ?>/>12:45 AM <option value="1:00 AM" is_value('1:00 AM')?' selected="selected"':''; ?>/>1:00 AM <option value="1:15 AM" is_value('1:15 AM')?' selected="selected"':''; ?>/>1:15 AM <option value="1:30 AM" is_value('1:30 AM')?' selected="selected"':''; ?>/>1:30 AM <option value="1:45 AM" is_value('1:45 AM')?' selected="selected"':''; ?>/>1:45 AM <option value="2:00 AM" is_value('2:00 AM')?' selected="selected"':''; ?>/>2:00 AM <option value="2:15 AM" is_value('2:15 AM')?' selected="selected"':''; ?>/>2:15 AM <option value="2:30 AM" is_value('2:30 AM')?' selected="selected"':''; ?>/>2:30 AM <option value="2:45 AM" is_value('2:45 AM')?' selected="selected"':''; ?>/>2:45 AM <option value="3:00 AM" is_value('3:00 AM')?' selected="selected"':''; ?>/>3:00 AM <option value="3:15 AM" is_value('3:15 AM')?' selected="selected"':''; ?>/>3:15 AM <option value="3:30 AM" is_value('3:30 AM')?' selected="selected"':''; ?>/>3:30 AM <option value="3:45 AM" is_value('3:45 AM')?' selected="selected"':''; ?>/>3:45 AM <option value="4:00 AM" is_value('4:00 AM')?' selected="selected"':''; ?>/>4:00 AM <option value="4:15 AM" is_value('4:15 AM')?' selected="selected"':''; ?>/>4:15 AM <option value="4:30 AM" is_value('4:30 AM')?' selected="selected"':''; ?>/>4:30 AM <option value="4:45 AM" is_value('4:45 AM')?' selected="selected"':''; ?>/>4:45 AM <option value="5:00 AM" is_value('5:00 AM')?' selected="selected"':''; ?>/>5:00 AM <option value="5:15 AM" is_value('5:15 AM')?' selected="selected"':''; ?>/>5:15 AM <option value="5:30 AM" is_value('5:30 AM')?' selected="selected"':''; ?>/>5:30 AM <option value="5:45 AM" is_value('5:45 AM')?' selected="selected"':''; ?>/>5:45 AMAnd here is the code I am using for the “event_details” metabox on the same page.
Event Type: the_field('event_type'); ?> <input type="radio" name="the_name(); ?>" value="public"is_value('public')?' checked="checked"':''; ?>/> Public Event <input type="radio" name="the_name(); ?>" value="members"is_value('members')?' checked="checked"':''; ?>/> Members Only Event Lcation City (required) the_field('event_location_city'); ?> <select name="the_name(); ?>"> Select a City <option value="San Diego" is_value('San Diego')?' selected="selected"':''; ?>/>San Diego <option value="Orange County" is_value('Orange County')?' selected="selected"':''; ?>/>Orange County <option value="Los Angeles" is_value('Los Angeles')?' selected="selected"':''; ?>/>Los Angeles <option value="Riverside" is_value('Riverside')?' selected="selected"':''; ?>/>Riverside Event Location Address (address & zipcode) the_field('event_location_address'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Pickup Location Address/Zipcode (optional) the_field('event_pickup_address'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Dropoff Location Address/Zipcode (optional) the_field('event_dropoff_address'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Name of Event Organizer (optional) the_field('event_organizer'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Email of Event Organizer (optional) the_field('event_contact_email'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Phone# of Event Organizer (optional) the_field('event_organizer_phone'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Event URL (optional) the_field('event_url'); ?> <input type="text" name="the_name(); ?>" value="the_value(); ?>"/> Other Important Notices (optional) the_field('event_notes'); ?> <textarea name="the_name(); ?>" rows="3">the_value(); ?> Enter any additional important notes you would like to mention to website visitors.I should point out that everything seems to be working perfectly when entering new events (one events per post) but I can’t seem to use the query_posts function to get those posts on the public site.
The other problem I just can’t seem to resolve is when I try to add more than one event start date/start time and end time to an individual post and then have the public site show a list of posts where all entries are shown for all posts and then sorted by the start date.
I believe I have totally confused myself here… ahhhh
I’m struggling with creating a conditional statement to check whether or not a custom write panel has been filled, and then providing that value or not depending. Thanks in advance!
Could you please show me a quick way how I could have a meta box automatically populate a list of existing “term” taxonomies. I am attempting to essentially utilize your code to create my own drop down list so that an editor can only select a single taxonomy term from such a drop down list? Thanks!!
@Ross, when you say write panel are you talking about a simple textarea? If so you can probably use some js to detect text entry… post a little bit of relevant code so I can help further.
@Binarybit, I think what you are looking for is the get_terms() function, I think this will return an array of terms which you then can create a dropdown from.
Hi Dimas,
I return with another question.
I am trying to use have_fields_and_multi in two places in the same metabox. It is not working right now because if I click add on the second “have_fields_and_multi” it will add to the first collection.
Any idea how to make it work in multiple instances ? I mean, this is not two nested have_fields_and_multi, so I think it’s only a JS problem.
Am I right ?
I will look into it, but let me know if you have any idea how to do this.
Horia, be sure to give your second add button the proper class name:
while($mb->have_fields_and_multi('docs')) ... <a href="#" class="docopy-docs button">Add Document</a> while($mb->have_fields_and_multi('authors')) ... <a href="#" class="docopy-authors button">Add Document</a>First: thanks for the powerful tool
I tried to find a way to use the class with
query_posts(” metakey=’my_meta’&meta_value=’my_value’ “) but i can’t find the right way to access the value as it is kindof serialized in db.
regards,
John.
John, take a look at: WPAlchemy MetaBox: Data Storage Modes, there is an example on how to use
query_posts()Dimas, that is perfect, I don’t know how I missed that.
Thank you !
@Dimas: This is EXACTLY what i was looking for! Sorry for not digging more into your blog! This is brilliant
Hi Dimas,
First of all thanks for sharing this class, it is very useful.
I want to report a little issue found when using have_fields_and_multi: it doesn’t work properly when the name given has dashes (-). I fixed it changing in line 431 \w for [a-zA-Z0-9_-].
Hope you want to add it in your next release.
Thanks!
Suso, thx for the tip. I’ve updated the current development version and the next tagged release will include this fix.
Dimas,
WPAlchemy seems to conflict with Wordpress 3′s featured image meta box. Do you know the reasoning for this?
Thanks,
Tyler
Dimas,
Just getting started with your code and I’m loving it, but then I’ve only just renamed meta.php and included it unmodified with my custom post type.
I agree with others that knowing how to do WYSIWYG and Media Library stuff is critical to having usable systems. It also doesn’t make sense to include it in your class, so since I need both, I’ll try to document it once I’m done and comment with the URL of the post…. If I remember.
But that’s not why I’m calling.
I discovered a (minor) bug in your code. I think its your JavaScript and I think its relatively easy to fix.
Load a new page with you meta.php metabox and go and remove all the documents.
Now first of all, this is meaningless since we don’t have any documents, so some checking in the JavaScript to see if it even makes sense to enable the button seems like a good idea.
In the dialog box that shows when you try to remove all, if you choose cancel, a new row appears. Unexpected to say the least. Not sure if this happens always, but certainly when you have no documents it happened for me (FF, OSX). Haven’t dug into it more, sorry.
@Tyler, can you explain what conflicting symptoms you are having with WP3 featured image meta box and WPAlchemy MetaBox? I will try to reproduce if I can?
@Adam, thx for the tip, I removed the auto “add” after a remove all so that things are a bit consistent … clicking “remove all” or clicking the last “remove item” button only leaves the “add item” button, however updating the page will cause a blank new item to reappear (I think this is expectable).
Dimas,
I figured it out. Of course the problem was on my end. Thanks for your time though.
Tyler
Hi,
thank you for that great piece of code & the detailed information.
I’d like to put a metabox right below the title (it will be the subtitle of the post).
It’s just the last piece to make it perfect for me. I didn’t find out how to use the $context property (i guess it has to be “advanced”) that way…
thanks a lot & keep the good work going on
Basti
from Munich
Hey Dimas, I found a MASSIVE error: in this post, for the “Using Include Options” example, you use an exclude option
Suso, thx for the tip, I’ve update the page!
Hi Dimas,
I just finished a development where I used your class, it was great, thanks again for sharing it.
I have a feature suggestion for the next release: adding taxonomy/term to the filters, besides post category and post tag. For my project I did a quick and dirty fix where I added a include_taxonomy option, and replaced wp_get_post_tags for wp_get_post_terms. I’m sure you can easily add the include/exclude taxonomy feature, and I think is a great addition to your class.
Thanks!
Also I found a problem. It doesn’t work making the query to the post with the meta fields in the header.php or footer.php, nor if is a template from get_template_part(). If I replace that code there inside a page it works. I guess is a problem with how you get the current post…
forgot to mention, what doesn’t work is the get_the_value() function.
Suso, there are situations which you may need to use
global $custom_metaboxto get proper access to the object …I may add a helper function such as
wpalchemy_get_instance('name')to help in these types of situations. There are parts of WordPress that run locally outside of the global scope, I am assumingget_template_part()is one of those situations.Yes! that fixed it, thanks for your help!
Simply amazing plugin!
I really hate to ask what feels like a stupid question… but when i try to use the sample template meta.php …. my meta box only shows the first text input and label. then it cuts off and doesn’t show any of the rest.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras orci lorem, bibendum in pharetra ac, luctus ut mauris.
Name
actually now i see the member_function() on a non-object error that was mentioned in the comments.
the line that is causing the choking:
<input type="text" name="the_name('name'); ?>" value="the_value('name'); ?>"/>
however, Scott’s statement that his error was coming from referencing $metabox outside the loop doesn’t help me solve it. the meta template isn’t in the loop at all is it? I did try to add global $metabox to the meta.php but that didn’t help.
perhaps it is just midnight and i am in a cake coma, but hopefully someone knows what’s up.
on another note i know you mentioned leaving the meta.php templates in our hands, but i had something a while back where the fields were defined in the $metabox array and it referenced a switch function by input type. then all i had to do was add this to the new metabox declaration array. i thought that was significantly easier and save repetitive coding (esp if you have multiple metaboxes), but maybe that is b/c I just can’t get this method to work yet.
'fields' => array(
array(
'name' => 'Headline',
'desc' => 'Enter the heading you\'d like to appear before the video',
'id' => $prefix . 'heading1',
'type' => 'text',
'std' => ''
),
array(
'name' => 'Textarea',
'desc' => 'Enter big text here',
'id' => $prefix . 'textarea',
'type' => 'textarea',
'std' => 'Default value 2'
) */
)
you can take a look if you want:
http://pastebin.com/91cQKKyq
thanks for sharing so much of your work!
So it was definitely the cake coma… for anyone else running into the member_function() on a non-object error problem check 2 things: first, that you are requiring the MetaBox.php file in the same place you are defining the $custom_metabox. for some reason you need this w/ classes. second, double check that you are using file paths for $custom_metabox’s template.
Now, to crank up some metaboxes. Thank you Dimas!
Hey Dimas,
I’ve run into a snag when trying to sort posts using the custom field data created by your class… I was wondering if you might be able to shed a little light on the subject?
I’ve created a question on the new WP stack exchange site here: http://wordpress.stackexchange.com/questions/1014/sorting-wordpress-posts-via-custom-field-values
It seems that for some reason, the query isn’t recognizing _events_meta[event_date] as a valid custom field key, but as you’ll see in the screenshot in that question, it’s stored in the database exactly like that.
Any ideas?
Hi Dimas – its Chris…
I was hoping that you could please review the comment post I made here on “August 9, 2010 at 8:37 pm” above… I don’t mean to sound impatient or ungrateful for all your help up to this point for me and other but I could really use your expert advice and I am stuck here… Thanks in advance!
This kicks ass..
You should throw up a donation box. I’d throw some cash your way.
Chris, I really apologize for not getting back to you. Can you email me your meta box template file, and your meta box definition (functions.php) so I can take a look?
Hey Dimas,
This is very helpful. Thanks!
I have one question you might be able to help me on. I would like to have a few checkboxes for the client to click which would display an icon (or a handful of icons – representing services they offer) on each post. Any help would be much appreciated.
Mike, take a look at the example code above for the meta box content (use the show/hide links), see line 106-108 for an example of setting up radio buttons, should be the same for check boxes. Remember to have the “value” parameter set to what ever identifier you need as a reference (for you icons, it could even be the filename or something).