965

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.

  1. Key Features and Benefits
  2. Defining a Meta Box is Easy
  3. Install and Setup (Video)
  4. Meta Box Setup Options
  5. The Guts of the Meta Box
  6. How to Use It! (show class methods)
  7. Repeating Field Groups
  8. Filter Specific Templates, Categories, Tags and Posts
  9. Using The Meta Box Values In Your Template
  10. Download
  11. 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

// include the class in your theme or plugin
include_once 'WPAlchemy/MetaBox.php';
// include css to help style our custom meta boxes
add_action( 'init', 'my_metabox_styles' );
function my_metabox_styles()
{
if ( is_admin() ) 
{ 
wp_enqueue_style( 'wpalchemy-metabox', get_stylesheet_directory_uri() . '/metaboxes/meta.css' );
}
}
$custom_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/custom/meta.php'
));

That’s it! The above code shows the basic definition needed to setup a custom meta box.

Tip Use WP_PLUGIN_DIR or WP_PLUGIN_URL if you are embedding wpalchemy in a custom wordpress plugin.

Install and Setup (Easy)

Tip Select 720 HD mode and watch it fullscreen or click the YouTube button to watch it on YouTube.

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 also appearing in the custom fields area.

title

'title' => 'Custom Meta'

This is the title of the meta box that appears in the WordPress UI.

template

'template' => STYLESHEETPATH . '/custom/meta.php'

You must define a template file for the contents of your meta box.

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’).

autosave

'autosave' => TRUE

Used to decide if meta box content should be autosaved.

mode

'mode' => WPALCHEMY_MODE_ARRAY // defaults to WPALCHEMY_MODE_ARRAY

Can be set to WPALCHEMY_MODE_ARRAY or WPALCHEMY_MODE_EXTRACT. Setting this option to WPALCHEMY_MODE_ARRAY (set by default) will cause the class to store all of its values as an associative array in a single meta entry. Setting this option to WPALCHEMY_MODE_EXTRACT will cause the class to extract all the first tier variables (fields) and create individual meta entries in the wp_postmeta table. This article has more info on this option.

prefix

'prefix' => '_my_' // defaults to NULL

When the mode option is set to WPALCHEMY_MODE_EXTRACT, you have to take care to avoid name collisions with other meta entries. The easiest way to do this is to add a prefix to your variables. This article has more info on this option.

Exclude / Include Options

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

Action / Filter Options

init_action

'init_action' => 'my_init_action_func' // defaults to NULL

Callback used on the WordPress “admin_init” action, the main benefit is that this callback is executed only when the meta box is present.

output_filter

'output_filter' => 'my_output_filter_func' // defaults to NULL

Callback used to override when the meta box gets displayed, must return TRUE or FALSE to determine if the meta box should or should not be displayed.

save_filter

'save_filter' => 'my_save_filter_func' // defaults to NULL

Callback used to override or insert meta data before saving occurs. The callback function gets passed two parameters: $meta (first param) meta box data array and $post_id (second param). You can also halt saving by returning FALSE.

save_action

'save_action' => 'my_save_action_func' // defaults to NULL

Callback used to execute custom code after saving. The callback function gets passed two parameters: $meta (first param) meta box data array and $post_id (second param).

head_filter

'head_filter' => 'my_head_filter_func' // defaults to NULL

Callback used to insert content into the <head> tag. Also used to override or insert <style> or <script> tags into the head.

head_action

'head_action' => 'my_head_action_func' // defaults to NULL

Callback used to insert content into the <head> tag.

foot_filter

'foot_filter' => 'my_foot_filter_func' // defaults to NULL

Callback used to insert content into the footer. Also used to override or insert <script> tags into the footer.

foot_action

'foot_action' => 'my_foot_action_func' // defaults to NULL

Callback used to insert content into the footer.

Display Options

hide_editor

'hide_editor' => TRUE // defaults to NULL

Used to hide the default content editor in a page or post.

hide_title

'hide_title' => TRUE // defaults to NULL

Used to hide the meta box title.

lock

'lock' => WPALCHEMY_LOCK_TOP // defaults to NULL

Used to lock a meta box in place, possible values are: “top”, “bottom”, “before_post_title”, “after_post_title”, it is recommened that you use the following constants to set the value of this option: WPALCHEMY_LOCK_TOP, WPALCHEMY_LOCK_BOTTOM, WPALCHEMY_LOCK_BEFORE_POST_TITLE, WPALCHEMY_LOCK_AFTER_POST_TITLE.

Using WPALCHEMY_LOCK_BEFORE_POST_TITLE or WPALCHEMY_LOCK_AFTER_POST_TITLE allows you to prevent other meta boxes from being dragged and dropped above or below your custom meta box. This is really useful when you are not using the editor (e.g. its hidden) and you want to have your own custom fields always at the top.

view

'view' => WPALCHEMY_VIEW_ALWAYS_OPENED // defaults to NULL

Used to set the initial view state of the meta box, possible values are: “opened”, “closed”, “always_opened”, it is recommended that you use the follwing constants to set the value of this option: WPALCHEMY_VIEW_START_OPENED, WPALCHEMY_VIEW_START_CLOSED, WPALCHEMY_VIEW_ALWAYS_OPENED.

hide_screen_option

'hide_screen_option' => TRUE // defaults to NULL

Used to hide the show/hide checkbox option from the screen options area.

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:

[+ show code]

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:

<?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:

$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:

$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.

$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:

$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.

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.

<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:

<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.

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.

<?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]
<?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[, $options])

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.

The $options param is an associative array which can contain the following values (each being optional).

$options = array('length' => 3, 'limit' => 10);

length: is the number of field groups to display initially (a minimum of sorts).

limit: is the hard limit at which point the “add new link” will stop working.

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:

<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.

<?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.

<?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.

<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().

<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.

<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.

new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/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.

new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/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.

new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/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

new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/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

new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/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

new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => STYLESHEETPATH . '/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:

// usually needed
global $custom_metabox;
// 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:

// 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.

965 responses to “WPAlchemy MetaBox PHP Class”

  1. Chris

    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-

  2. Chris

    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.

  3. Scott Lee

    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?

  4. Scott Lee

    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.

  5. Samuel Arendt

    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.

  6. Scott Lee

    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

  7. Scott Lee

    Never mind, I’m an idiot. I was calling the value too soon. Like before the Loop too soon.

  8. Scott Lee

    Thank you Dimas! It worked brilliantly.

  9. nicolas

    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.

  10. Nicolas

    ok thanks!
    it’s works with:

    global $custom_metabox3;
    $custom_metabox3->the_meta();
    
  11. micha

    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.

  12. micha

    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.

  13. micha


    $clients[$mb->get_the_index()]; ?>

    that gives an ugly 500 😉 i now use

    get_the_index()]->post_title; ?>

    which is sub-optimal too but at least it works for testing purposes …

  14. josh

    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?

  15. Josh

    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.

  16. Josh

    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.

  17. Josh

    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.

  18. Josh

    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.

  19. Scott Lee

    Josh, I too think this would be a great feature. Have you had any luck coming up with a workaround?

  20. Josh

    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.

  21. Chris

    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.

  22. Ross

    +1 on #5 . How to add WYSIWYG to meta box, and/or HTML/Visual mode toggle.

  23. Chris

    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!

  24. Chris

    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!

  25. Chris

    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!

  26. Louisa

    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

  27. Louisa

    Thanks Dimas!!!!

  28. Josh

    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>
    
  29. Josh

    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>
  30. Josh

    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?

  31. Josh

    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.

  32. Said

    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.

    $sidebar_content = get_post_meta($post->ID,'_sidebar_content',TRUE);
    echo($sidebar_content['_column_one']);
    

    Thanks & Regards
    Said

  33. Horia Ancas

    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

  34. Tyler

    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

  35. Horia Ancas

    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.

  36. Tyler

    Horia,
    Thanks for the reply. I tried implementing your technique and it didn’t seem to work. I appreciate the help though!

    Tyler

  37. Tyler

    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

  38. Ben Davis

    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

  39. Chris

    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 AM
    

    And 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.
    
  40. Chris

    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

  41. Ross

    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!

  42. Binarybit

    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!!

  43. Horia Ancas

    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.

  44. John

    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.

  45. Horia Ancas

    Dimas, that is perfect, I don’t know how I missed that.
    Thank you !

  46. John

    @Dimas: This is EXACTLY what i was looking for! Sorry for not digging more into your blog! This is brilliant 😉

  47. Suso Guez

    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!

  48. Tyler

    Dimas,
    WPAlchemy seems to conflict with WordPress 3’s featured image meta box. Do you know the reasoning for this?

    Thanks,
    Tyler

  49. Adam van den Hoven

    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.

  50. Tyler

    Dimas,
    I figured it out. Of course the problem was on my end. Thanks for your time though.

    Tyler

  51. Basti

    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

  52. Suso Guez

    Hey Dimas, I found a MASSIVE error: in this post, for the “Using Include Options” example, you use an exclude option :)

  53. Suso Guez

    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!

  54. Suso Guez

    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…

  55. Suso Guez

    forgot to mention, what doesn’t work is the get_the_value() function.

  56. Suso Guez

    Yes! that fixed it, thanks for your help!

  57. Richard van den Winkel

    Simply amazing plugin!

  58. Kathy

    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!

  59. Kathy

    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!

  60. Josh

    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?

  61. Chris

    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!

  62. Mark

    This kicks ass..

    You should throw up a donation box. I’d throw some cash your way.

  63. Mike

    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.

  64. Mike

    Thanks Dimas, I was able to get everything working correctly except for the checkboxes which are always checked even after unselected and published. When I refresh they are all checked again. Here is my meta.php. Thanks in advance for any help.

    Optional features that will show up on each listing.
    the_field('icon1'); ?>
    <input type="checkbox" name="the_name(); ?>" value="" get_the_value() echo 'checked="checked"'; ?> Wifi Available
    the_field('icon2'); ?>
    <input type="checkbox" name="the_name(); ?>" value="" get_the_value() echo 'checked="checked"'; ?> Pet Friendly
    the_field('icon3'); ?>
    <input type="checkbox" name="the_name(); ?>" value="" get_the_value() echo 'checked="checked"'; ?> Handicap Friendly
    the_field('icon4'); ?>
    <input type="checkbox" name="the_name(); ?>" value="" get_the_value() echo 'checked="checked"'; ?> Chef Kitchen
    Specials Subtitle
    <input type="text" name="the_name('specials'); ?>" value="the_value('specials'); ?>"/>
    
  65. Tom Stone

    Thank you for your wonderful metabox class! I’ve been able to pull off some rather nifty things thanks to WPAlchemy MetaBox.

    However, now I’ve run into a problem that seems impossible to solve (for me, that is), and I wonder if you might take pity on my pain. :)

    I have a custom post type called “performers”, where the posts are bios of various stage performers – where I’ve used WPAlchemy MetaBox for the performers’ contact info etc. Everything works perfect here.

    Now, I’ve also made a custom post type called “showprogram”, and here I’m trying to make a meta box (“Appearing this week”) that have a dropdown select box with the names of all the performers from the “performers” post type – as well as an “add artist” button that can duplicate the select box.

    But I’m quite stuck. I’ve managed to populate the select box with the performers’ names, but nothing gets saved. I think my whole approach is wrong, but can’t think of another way.

    Any thoughts or wise sage advise?

  66. Josh

    Hey Dimas,

    I know you’re probably getting tired of me poking around and asking question after question… but I’ve got yet another one for you! lol

    I’m trying to use your class to include a group of checkboxes (much like Mike above) and I’ve figured out how to take the data from WPAlchemy (which is already stored as an array) and add another array within it…

    Like so:

    <?php
    $services_deliver = 'One-on-One Coaching, Telephone Coaching, Face-to-Face, Team Coaching, Retreats, Facilitation, Keynote Speaking, Workshops, Teleseminars, Custom Designs';
    $services_array = explode(', ', $services_deliver);
    ?>
    Services or Delivery Methods
    <?php foreach($services_array as $service) { ?>
    the_name('services'); ?>[]" value="<?php echo $service; ?>"<?php echo $mb->is_value("[$service]")?' checked="checked"':''; ?> /> <?php echo $service; ?>
    <?php } ?>
    

    However, when trying to tell if the checkbox should be checked or not, that’s when I run into a problem…

    I tried using the example you gave for radio buttons with “is_value()”, but since the “value” is also an array of values, I’ve not yet been able to figure out how to check each value[value] to see if a checkbox should be checked or not…

    Any ideas?

  67. Josh

    Ok, so with a little more digging I’ve found that the $mb object is being stored as so:

    WPAlchemy_MetaBox Object
    (
    [id] => _userdata_meta
    [title] => Custom User Data
    [types] => Array
    (
    [0] => post
    )
    [context] => normal
    [priority] => high
    [template] => /home/vps_useracct/domain.me/wordpress/wp-content/themes/twentyten/WPAlchemy/custom/userdata.php
    [autosave] => 1
    [mode] => array
    [prefix] =>
    [exclude_template] =>
    [exclude_category_id] =>
    [exclude_category] =>
    [exclude_tag_id] =>
    [exclude_tag] =>
    [exclude_post_id] =>
    [include_template] =>
    [include_category_id] =>
    [include_category] => Array
    (
    [0] => User Data
    )
    [include_tag_id] =>
    [include_tag] =>
    [include_post_id] =>
    [save_filter] =>
    [save_action] =>
    [meta] => Array
    (
    [email] => me@domain.me
    [website] => http://domain.me
    [phone] => 555.123.1212
    [address1] => 123 Some St.
    [address2] => Apt #2
    [citystatezip] => Some City, ST 12345
    [services] => Array
    (
    [0] => Face-to-Face
    [1] => Retreats
    [2] => Workshops
    [3] => Teleseminars
    )
    [educerts] => yep
    and
    this
    and
    that
    [bio] =>
    Hello, this is a paragraph of my bio...
    * I love ducks
    * I love animals
    * I love dogs
    )
    [name] =>
    [subname] =>
    [lenth] => 0
    [current] => -1
    [in_loop] =>
    [in_template] => 1
    [group_tag] =>
    [current_post_id] => 78
    )
    

    So this means that the “services” item is being stored as an array within the original array… So why am I not able to access it’s data no matter what configuration of $mb->is_value() I use?

  68. Josh

    You sir, are a Godsend! hahaha

    I was actually JUST hacking together something that worked… but booooy was it nasty and messy! lol

    I’m glad you’re listening to our issues and actually taking action. There are so many developers on the web who release things and never work to implement their users’ ideas… They could stand to learn a thing or two from you.

    Thanks!

  69. Josh

    Sweet!

    Got it working by using:

    <div class="checkbox-group">
    <h6>Services or Delivery Methods</h6>
    <?php foreach($services_array as $service) { ?>
    <label><input type="checkbox" name="<?php $mb->the_name('services'); ?>[]" value="<?php echo $service; ?>"<?php $mb->the_checkbox_state('services', $service); ?> /> <?php echo $service; ?></label>
    <?php } ?>
    </div>
    
  70. Josh

    Great, thanks for the tip!

  71. Josh

    Ok, I don’t know if I’ve stumbled onto the first bug with your latest release or not… but something strange is happening.

    Normally, when accessing the custom data in the theme, there’s no issue at all (with earlier versions)… However, now it seems that when I try to use something like $userdata_metabox->get_the_value('phone') it’s actually just repeating one value over and over and over all throughout the loop of posts.

    I’ve checked, double checked, and triple-checked to try to make sure I haven’t done anything to screw it up, but I can’t find anything erroneous on my end.

    Here’s an example bit of code:

    <div style="display:none;">
    <?php global $userdata_metabox; query_posts('cat=91&posts_per_page=-1'); if(have_posts()) : while(have_posts()) : the_post(); ?>
    <?php echo 'The Post ID is: '.get_the_ID().' '.get_the_title().'\'s Phone Number is: '.$userdata_metabox->get_the_value('phone').' and their user_id is: '.$userdata_metabox->get_the_value('user_id').' and their email address is: '.$userdata_metabox->get_the_value('email').'<br />'; ?>
    <?php endwhile; endif; ?>
    </div>
    

    The above bit of code returns the following:

    <div style="display: none;">
    The Post ID is: 1379 Ronnie Grabon's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>  
    The Post ID is: 1376 Pamela Corbett's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>  
    The Post ID is: 1373 Melodie Howard's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>  
    The Post ID is: 1370 Mary Kralj's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>  
    The Post ID is: 1367 Martha Tilyard's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1364 Lynne Alexander's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1361 Lily Kelly-Radford's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1358 Karen Corsaro's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1348 John Alexander's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1351 Joyce Richman's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1345 Geoff Grenert's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1342 Donna Riechmann's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1339 David Hurst's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    The Post ID is: 1331 Barbara Demarest's Phone Number is: 336-297-0483 and their user_id is: 19 and their email address is: RGrabon@triad.rr.com
    <br>
    </div>
    

    Notice that the phone number, user ID, and email address stay the same no matter which post is referenced in the loop. The “name” given is actually each post title, and you can tell by the name and the post ID, that the loop is running correctly.

    It’s just not pulling the correct post meta from the wp alchemy class for some reason. I’ve also double checked the database to ensure the data is stored correctly, and it is. Each post has it’s own unique set of “user data” stored under _userdata_meta

    Strange…

  72. Josh

    w00t! Thanks dude… I know you’re probably getting tired of my incessant nagging by now, eh? hahaha

  73. Josh

    Ok, so I know I’m a loser with no life… but I’ve run into something else that’s a bit curious…

    I have a group setup, and it all works well as it should. However, if I run an if() statement on have_fields() to check to see if it does in fact have any information stored, then the while() loop only shows a couple of the available informations…

    Example:

    <?php if($userdata_metabox->have_fields('testimonials')) : ?>
    <h2>Testimonials</h2>
    <?php while($userdata_metabox->have_fields('testimonials')) : ?>
    <blockquote><?php $userdata_metabox->the_value('quote'); ?><cite><?php $userdata_metabox->the_value('personcited'); ?></cite></blockquote>
    <?php endwhile; endif; ?>
    

    That shows the first 2 “testimonials stored in that group… but there’s actually 3… If I remove the if() statement though, then it displays all 3 as it should…

    I just need to be able to check for the existence first so that I don’t show the heading that says “Testimonials” if there’s none filled out for that particular user.

    Any ideas?

  74. Josh

    Hmm… I tried using $location_mb->have_value() and that gave me: “Fatal error: Call to a member function have_value() on a non-object”

    However, oddly enough… After changing it back to what it was previously… The testimonials display now… All of them. ???????

    The code now is exactly the same as it was before the error… Why did it start working? hahahahaha

  75. Gavin Weeks

    Hi Guys,

    Great tutorial, but having a small problem. I am trying to do something a little more advanced (in my eyes) than this tutorial covers. I am hoping someone can help me.

    I am using the data from a custom metabox in a random loop. However as the metabox isn’t always filled in it outputs an empty container.

    What I would like to do is to only display meta box info where data exists and just ignore posts where the meta is empty.

    Anyone have any ideas that could help me? It would be greatly appreciated.

    Hmm I don’t seem to be able to paste my code without it stripping bits out even using the code tag. How did others do it?

  76. Josh Byers

    It would seem to me that it would make a lot of sense to be able to use your class in styling meta boxes for custom taxonomies.

    Case in point: I’m in the middle of developing a real-estate theme and in the past I would have just created a number of custom fields to hold the data and your class would be perfect.

    But now that WordPress is moving forward with the addition of custom taxonomies it makes a lot of sense to move things that were previously custom fields to be taxonomies. There are a number of native functions and options available to taxonomies that are not to custom fields.

    So that said I would love to see your class be able to incorporate custom taxonomies – not just pull in the data from get_terms but actually save it out to the proper table.

    I ran across this tutorial which will allow you to do this but it doesn’t have the elegance or ease of your meta box class.
    http://shibashake.com/wordpress-theme/wordpress-custom-taxonomy-input-panels

    Thanks.

  77. Tim

    Dimas,
    Is there anyway to make a text field’s onChange function work while enclosed in the group tags for multi fields? My onChange function seems to work great when not treated as a group, but i want to be able to “Add” fields. Thanks a lot for your help!

  78. Cracks

    Is there a (correct) way to create a textarea with the WordPress WYSIWYG Editor? I was using the secondary_content HTML plugin (http://www.cmurrayconsulting.com/software/wordpress-secondary-html-content/) which is excellent, and by-default loads the WYSIWYG editor.

    But just now I discovered WP Alchamey, and I’m immediately converted. Wow – what a weapon to add to anybody’s WordPress toolbox! Very impressive and professional Dimas.

    So I was wondering if someone can advise on the mce editor addition.

  79. Josh Byers

    Awesome. This would be huge to get this working.

    So, here is what I have for my custom meta box.

    <select name="the_name(); ?>">
    $taxitem) {
    echo 'slug .'"'; $thevalue = $taxitem->slug; if ($metabox->get_the_value() == "$thevalue") echo $selected; ?> 
    ' . $taxitem->name .'';
    }
    ?> 
    

    This code is getting the terms for the custom taxonomy just fine. And your class saves my selection but it does not translate to the actual taxonomy. I suspect I’m missing something from the save action.

    What (if anything) do I need to add to the save action? I’ve replaced the ‘category’ placeholder with ‘property-location’

    Thanks.

  80. Josh Byers

    One thing I forgot to add is that the first time I saved from the custom select box it removed what was selected in the actual taxonomy box.

    And now even if I check off something in the actual taxonomy box it does not get saved. (but what is selected in the custom select box gets saved)

  81. Josh Byers

    I’m using the term ID now and the regular taxonomy saves as expected but there is no change to the custom meta select box.

    I can’t get the code to post correctly for my custom meta box so here is a link:
    http://snipplr.com/view/40439/select-box-for-wp-alchemytaxonomy/

    This is my custom save function:

    function my_save_action($meta, $post_id)
    {
    $theTermId = get_term_by( 'id', 'property-location' );
    $theTermId = $theTermId->ID;
    // use the category/taxonomy ids (using 'category' as taxonomy example)
    // see: http://codex.wordpress.org/Function_Reference/wp_set_post_terms
    wp_set_post_terms($post_id, array(3), "$theTermId", FALSE);
    }
    
  82. Chris

    Hi Dimas – I noticed something today while diagnosing a wordpress issue…. It seems that your metabox-function file is including a BUNCH of javascript code into the head and footer of every page of the admin side. I noticed this when viewing the source of various admin pages which were not the post-edit edit page. The files I am referring to related to the copy/delete actions above the and there is also a bunch of code being loads into the footer div which is duplicated for every metabox created in the system.

    Would there be a way to modify your functions file so the code is only included on the post-edit screen. I used the following code below to only include a specific css file the admin page being loaded was the post.php, post-new.php or edit.php pages. I believe for the code in question it only needs to be loaded on the post.php and post-new.php page as your class does not effect any other admin pages.

    Here is the code I am using which might be of help:

    global $pagenow;
    if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='edit.php' OR $pagenow=='post.php') wp_enqueue_style('custom_meta_css', _TEMPLATEURL . '/custom/admin-metaboxes/css/metabox-styles.css');
    
  83. NetConstructor

    Just thought of something which I don’t think your class took into account. While I personally don’t need this ability but I am assuming other as well as myself might in the near future.

    So, in your class, when you create/define a new metabox through the functions.php file and want this metabox to become available on two separate post types you one would use:
    types’ => array(‘news’,’articles’)

    So, far so good – but lets say you define some specific additional variables such as the priority, lock, view, or other variables… Now, let’s assume that I only want these additional settings set for one of those two post types like “news” and for the other post type (articles) I want to set different variables. Can this easily be done? If not, maybe it would make sense to be able to override these “variable display settings” on a per post type basis. Also, now that I am writing this maybe the same type of override should exist for your include/exclude options so individual settings could be coded/defined depending on the needs of the developer. Just a thought…

  84. Josh Byers

    Hey Dimas,

    Thanks for the help – unfortunately I have not been able to get it work.

    Short of asking someone to do it for me, I don’t think I will figure it out at this point – my coding skills are being stretched to new heights :)

    If I do figure it out I’ll be sure to post back here so others can know as well – just didn’t want to leave the issue hanging.

  85. safwan erooth

    Your class fails when used in child theme as TEMPLATEPATH points to the parent theme. Use of STYLESHEETPATH may solve the problem.

    Anyway it’s a wonderful work that you have done. Thanks

  86. safwan erooth

    That would be great… Thanks again for your wonderful contribution.

  87. Safwan

    Can custom taxonomy be filtered using similar technique… I mean show a custom taxonomy only for certain category?

  88. NetConstructor.com

    @Josh – Hey Josh… I was working with Dimas on this issue as I needed a solution as well and wanted to share with you how this can be accomplished which works like this:

    Utilizing his WPAlchemey Class I added a save_action var into the area of my functions.php file where I am defining the metabox – This code looks like this: (NOTE: I am using the taxonomy “category” which of course you can change to whatever your custom taxonomy might be):

    'save_action' => 'save_taxonomy_terms',
    

    I then add the following function for this save action like this:

    function save_taxonomy_terms($meta, $post_id) 
    {
    wp_set_post_terms($post_id, array($meta['my_terms']), 'category', FALSE);
    }
    

    An my metabox code which displays the dropdown list of taxonomies looks like this:

    <?php $terms = get_terms('category', 'hide_empty=0'); ?>
    <?php $mb->the_field('my_terms'); ?>
    <select name="<?php $mb->the_name(); ?>">
    <?php foreach ($terms as $term): ?>
    <option value="<?php echo $term->term_id; ?>"<?php $mb->the_select_state($term->term_id); ?><?php echo '>' . $term->name; ?></option>
    <?php endforeach; ?>
    </select>
    

    Hope this help you and others!

  89. NetConstructor.com

    I just noticed a potential problem with this code which I have not been able to resolve. The code I have pasted above seem to only work when the taxonomy is setup with ‘hierarchical’ => true. If you set this value to false then for some reason it creates a new term based on the term ID of the one you selected. Does anyone happen to know what the save_action function need to be changed to if the hierarchical?

  90. Chris

    Has anyone figured out a way to resolve this?

  91. Matt

    Hi Dimas,

    I’ve got an error, why I can’t call the method ?
    Fatal error : Call to a member function the_name().

  92. Faye

    This class is proving completely invaluable in a charity website project I’m working on – thank you for all your work on it, Dimas.

    I have a question about the have_fields_and_one feature. I love the principle of it, and I’m using it to enable my client to add any number of links to be displayed on certain pages of their site. However, as I’m wrapping the output in a series of tags, the unfortunate effect of the and_one is a final empty , which is showing up styled like a normal list item, but (obviously) empty. Is there any way around this?

    This is the code I’m using in my template to output the links:

     the_meta();
    // loop a set of field groups
    while($custom_metaboxp->have_fields_and_one('portfoliolinks'))
    { ?>
    <a href="the_meta(); $custom_metaboxp->the_value('url'); ?>">the_meta(); $custom_metaboxp->the_value('linktext'); ?>
    

    Thank you!

  93. Faye

    …and, hmm, my code didn’t output right there at all, but hopefully you’ll get the idea – I have link tags wrapped around each link that’s output by the metabox using have_fields_and_one.

  94. Steve

    I might have missed this above, but do you know how one would set a radio button to be checked by default? It doesn’t look like this is an option that is built into your class. Thanks so much for sharing this code!

  95. Ross

    Sorry if this has been answered already. In my template there’s seems to be a problem when I run other custom loops with get_posts before executing my meta box values. Even if I declare global $my_metabox; somehow a conflict exists and my meta values won’t output.

  96. Ross

    Downloaded lastest version. But not sure I explained my issue properly. Maybe I’m simply using the class wrong. Trying to write a conditional like so:

    get_the_value(‘link’)) { ?>
    // do something

    I’m also running get_posts loops on the page and they don’t let the above function execute. No errors, just no output.

  97. Tom Stone

    Version 1.3.5 broke the metaboxes. Old posts, already saved, shows – but on new posts, the metaboxes are nowhere to be seen.

    After reverting to version 1.3.4, everything is fine again.

  98. Chris

    Dimas, could you look into the taxonomy problem listed above… Strange situation happening there which requires the tax to be hierarchical for it to work.

  99. Jason Loftis

    Dimas, this is an excellent WP resource. Thank you.

    I would like to create a metabox that relates a post to other posts. The website is for a bicycle racing series. The metabox would appear in a post about a particular race. I want to be able to use a multiple select field to assign sponsors to that race. Each sponsor is an entry in a custom post type.

    Thus, inspired by the discussion on here regarding using a select field to assign taxonomy terms, I was able to successfully create a multiple select field in a metabox that queries the “sponsor” custom post type.

    <?php
    $sponsor_query = new WP_Query;
    $sponsor_list = $sponsor_query->query(array('post_type' => array('sponsor','shop'),'posts_per_page' => '-1','orderby' => 'title','order' => 'asc'));
    $getsponsornav = array();
    ?>
    <?php $mb->the_field('event_sponsors', WPALCHEMY_FIELD_HINT_SELECT_MULTIPLE); ?>
    <select name="<?php $mb->the_name(); ?>" multiple="multiple" size="5" style="height:75px;">
    <?php foreach($sponsor_list as $asponsor) : ?>
    <option value="<?php echo $asponsor->ID; ?>"<?php $mb->the_select_state($asponsor->ID); ?><?php echo '>' . $asponsor->post_title; ?></option>
    <?php endforeach; ?>
    </select>
    

    But when I make selections and click “update” in the post editor, I get a white screen full of code. I’m presuming that the problem is that the selections aren’t properly saving. I’m a newbie to some of these coding techniques, so I’m wondering if I need to create a “save_action” like you did in the taxonomy example? I tried the following custom save_action:

    function save_sponsors($meta, $post_id)
    {
    var_dump($meta['event_sponsors']);
    var_dump($post_id['event_sponsors']);
    exit;
    return $meta;
    }
    

    This reduced the amount of code that appears after trying to unsuccessfully update the post to this:

    array(1) { [0]=>  string(3) "535" } string(1) "2" 
    

    I’m sure there is something simple that makes what I’m trying to do possible, but I’m not aware of it in my ignorance. Hopefully, this clearly presents the spirit of what I’m trying to accomplish and you may quickly point me in the right direction. I appreciate your help. Perhaps there are others that want to do something like this and this comment will help them too.

  100. DAniele M

    Nice lib!!! i like it really!
    Do you have a discussion group?

  101. Kathy

    Hi Dimas,

    I was wondering if there was a way to include/exclude meta boxes based on post types? For instance, if I want a metabox to appear on every page? I know this is part of the wp code, but I don’t see it in your docs for include/exclude.

    Cheers,

    -kathy

  102. kathy

    awesome! i feel like a moron for missing that. thank you dimas for a super, complete php class.

  103. Chris

    Hi Dimas – I have conducted various tests and my records are showing that your class is creating multiple PHP errors related to a specific line on the MetaBox.php file. My logs shows multiple entries for the following:

    PHP Warning: Invalid argument supplied for foreach()

    More specifically, each entries is referencing line 1973 of your MetaBox.php file (which I renamed and relocated btw).

    When reviewing line number 1973 within your code it related to this:

    foreach ($new_data as $k => $v)

    Note – I am using the newest dev version 1.3.8 in case that helps. What can we do to resolve this or what might this be related to?

  104. Maggie

    Hi Dimas,

    Thanks for this great plugin!

    I just run into one thing I can’t figure out. I want to use a checkbox to let the user indicate if they need a “print friendly” option for the page (so check to add the “print this page” link). I use the WP-Print plugin for this. In my template I would like to add the code to get the checked/unchecked value for the link and if checked display the link.

    This is what I came up with in my template file:

    the_meta();
    if ($meta['print']) echo do_shortcode('[print_link]');
    ?>

    I used your example for the no-follow checkbox to make the metabox, that works fine. But how to make the link appear? Also if I put some word instead of the do_shortcode thing, nothing appears. What am I doing wrong?

    If you have any idea, that would be greatly appreciated!

    Thanks,
    Maggie

  105. Maggie

    Sorry to have troubled you, have figured it out already by using the

    if ($custom_metabox->have_value('your_value')) : 

    and a tweak in the wp-print plugin. Turns out it doesn’t work out-of-the-box when using custom post types.

    Thanks!
    Maggie

  106. Mike Truese

    Really lost and struggling here…

    I have 2 custom post types (ABC and DEF).
    ABC was set up with $custom_metabox and DEF setup with $custom_metabox2.

    The admins work perfectly, add/edit/save all quite lovely!

    On the front, I am using custom page templates to show a table of posts, and then a click to show details.

    for ABC, this worked great, got the values I need into the table by field.

    for DEF ( $custom_metabox2), it’s not working – the issue is, for content that is not required (say an optional field) if post 1 has the value, but post 2 does NOT (empty), it’s pulling the value from post 1 until a new post has a new value.

    In the loop, I can see the post ID is changing (did an echo).

    It’s like the loop is holding on to a value, so empty fields are returning the value.

    BTW, I tried to use the lastest MetaBox from git, and that broke my ABC working version. So I went back to the ver I have (a few months old, I can’t tell how to figure out version).

    Really lost, and client is breathing on my neck.

    Please help!

  107. Ricardo

    Every time I update the page a new blank field set is created below the existent ones. Shouldn’t that only happen if there are no fields at all? After a few edits to a post you end up with a box littered with empty fields.

  108. Ricardo

    That is, using `have_fields_and_multi`.

  109. Ricardo

    It seems like .wpa_group.tocopy is sticking around on publish, so it comes in on the next page load. I’m removing it on clicking #publish as a fix.

  110. Mike Truese

    Part solved:
    For the working table page, that ‘broke’ with latest release, it worked again when I put:
    global $custom_metabox;
    $custom_metabox->the_meta(get_the_ID());
    in the loop.

    I tried this for the totally non working version, and I still got repeated values when a field was optional.

    My workaround was to go with this:
    get_post_meta(get_the_ID(),$custom_metabox2->get_the_name(‘fleet-golfbags’)

    which would show empty if a field had no value for that record, or the new value when the field changed.

    What it seems is that the loop is not clearing out the values in the meta-box custom object. Going oldschool, to the metal (so to speak) bypasses the custom object and gets the value (or non-value) directly.

    Is there something I am not doing right? Or perhaps, just perhaps, the custom meta object needs a cleanout on each loop?

  111. Justin Myers

    Dimas,

    I can’t figure this out for the life of me and haven’t seen anyone else run into this yet.

    I have a custom loop inside of my metabox display file so that I can link a “article” post to another custom post by using a dropdown. The problem I’ve run into is that when I go to edit an “article” or create a new one, it seems as though the query from the metabox is running and taking over because the new or one I’m trying to edit displays data from metabox loop.

    As soon as I take out that custom loop everything works just fine again. Is there some reason this custom query would be carried over onto another screen?

    There’s nothing strange about the query and I’ve confirmed that if I take out the while loop everything starts working fine again.

    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 
    <option value="the_ID();" 
    <?php if ($metabox->get_the_value() == get_the_ID()) echo $selected; ?>>
    </option>		
    <?php endwhile; ?>
    
  112. Justin Myers

    Got it working by just storing the global $post variable in a temp variable and then restoring it after the loop. Thanks for the help.

  113. Luke

    Would it be possible to use this class to for Theme Developers to create a theme options page? It may be out of the scope of the class.

    It would be great if under the Appearance Menu, a “Theme Options” menu item would show. It would be there that the custom metaboxes would be available. This may be a different class in and of it self but, essentially, seems to have the same functionality.

    It may be possible to incorporate an “options” type for the WPAlchemy_MetaBox array (e.g. page, post, event).

    Currently I have theme options, located under the Appearance menu. Everything works great. However, it would be supra awesome if there was a class like this one to easily be able to add options and pull theme into the theme.

  114. Luke

    Dimas,

    I’m hoping you can help me as I am at a loss. I’ve got the script setup and working very nicely. I am using an example from your full_meta.php where you have the adding and removing documents example.

    I can add, remove all, and or remove single “groups”, in my it’s case links. The problem I am having is each time I Update the page or post, it’s adding another instance. Before updated screenshot and After update screenshot.

    When I use your “docs” group code, I don’t have any problems. I must be missing something small. Here is what I have so far.

    have_fields_and_multi('links')): ?>
    the_group_open(); ?>
    the_field('title'); ?>
    Link Title
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Link URL
    the_field('link'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>Example:http://www.celtic7.com
    Link Target
    the_field('target'); ?>
    <select name="the_name(); ?>">
    <option value="_self"get_the_value() == '_self') echo $selected; ?>>_self
    <option value="_blank"get_the_value() == '_blank') echo $selected; ?>>_blank
    <option value="_parent"get_the_value() == '_parent') echo $selected; ?>>_parent
    <option value="_top"get_the_value() == '_top') echo $selected; ?>>_top
    <a href="#" title="Remove link" rel="nofollow">X</a>
    the_group_close(); ?>
    <a href="#" title="Add new link" rel="nofollow">Add Link</a>
    
  115. Luke

    Ofcourse, after I spend hours and finally submit my plea for help, I figure it out!

    Turns out the group was duplicating because of the select box not having an empty option first in the list . I initially took it out so the link would always have a value upon being saved. It didn’t matter what the value was, it would duplicate unless there was an empty option first in the list.

    I can’t wait for your AdminMenu script! By the way, you need a donate link for all of the script goodness.

  116. Luke

    I have one feature idea and two issues regarding the while ( $custom_metabox->have_fields_and_multi('links') loop.

    First, the while ( $custom_metabox->have_fields_and_multi('links') loop:
    I have a “Hello World” post with two “links” groups. One link is to Google and one to Yahoo (screenshot). Using the while ( $custom_metabox->have_fields_and_multi('links') loop i get the results, however, two odd things are happening.

    1) I get both the Google and Yahoo results PLUS an empty result at the end (screenshot).

    2) The meta data of one post is showing up on each subsequent posts, that do/do not have any custom_metabox values assigned to them. Example: Hello World (with meta data assigned) and Another Post (w/o meta data assigned). You can see the values of “Hello World” post are being carried over (the Google and Yahoo info). Here are each posts setup screenshots – Hello World and Another Post.

    Here is an example of my post loop.

    Feature Idea: As great as this script is, I think it would be an added value if drag n drop was included in the have_fields_and_multi functionality. It would be nice to arrange the order of the groups. As it stands, you can create and remove groups, and display them in that order. It would be even more dynamic if the possibility was there to arrange those items. Say I have a list of 6 groups, and for some reason, needed the 6th one to be first. I would have to remove all groups, then add the info back in the order I would like. Nothing big as the script is a lifesaver in and of itself, this would just be double bonus for me.

  117. Luke

    Thanks, Dimas!

    For #2, your suggest worked however, it appears that #1 gets worse by adding an additional (now 2) empty results on posts without an values assigned (screenshot 1). This is what the source code is showing:

    footer class="action">
    a href="" title="">» 
    a href="" title="">» 
    /footer>
    

    For what it’s worth, say I call the $custom_metabox->have_fields_and_multi('links'); anytime before the while($custom_metabox->have_fields_and_multi('links')) loop, one of the empty results goes away (screenshot 2). And for whatever reason I call it again (a third time, now), another goes away (screenshot 3).

    If it helps to replicate what I have, here is my custom metabox code.

    By the way, a ordering groups by number would be just as awesome as drag n’ drop.

  118. Luke

    I was using version 1.3.7, just downloaded yesterday or the day before from here. I’ve updated to 1.3.11 and made the change as suggest. No difference either way.

  119. Luke

    Dimas, it works beautifully! I’m especially grateful.

  120. Luke

    Dimas, I was curious if you had a way to Save/update the post via a button. I noticed the save_action and save_filter callbacks. Basically, I am looking for a way to insert the default blue “Update” or “Publish” button to do just that. Some plugins I use, use this functionality. Sometimes, it’s nice to not have to scroll back to the top to save/update. Is this built in?

  121. Luke

    Excellent! Thanks.

  122. Luke

    Dimas, I’m back with another (similar) issue with the have_fields_and_multi() this time in the admin section.

    Similar to the issue before of an unwanted extra NULL value being added to the page, this time it is being added to the metabox. However, this extra value does not show up, which seems like everything is working fine. This may be why the extra value was showing up on the page before as well?

    I found this because I was using the is_last() call to check and see if the group was the last group. If it was, I was going to have it show a button to add another group. When it wasn’t working, I looked at the source code and found the extra group (which then echoed my is_last test).

    I thought I would share as it may shine some light onto the other issue, although you did fix it.

  123. Luke

    Dimas, I am using the_group_open() and the_group_close(). Here is a link to my code snippet.

  124. Ross

    Dimas – how about starting a forum? This comments list is getting looooooong. And then we can all help each other. :)

  125. Chris

    Hey Dimas – have you looked into using the built in wordpress export tools and then reimporting the file into a fresh wordpress install (same version) with the theme preactivated? I am not sure why but it seems things did not get associated correctly after the import because everything imported correctly except for any data created by your metabox….

    Please also do look into those two issue I mentioned to you by email as I still have not been able to resolve it.

  126. Sidne

    Hi Dimas, what a great plugin you’ve coded! b^^d

    I have a question, is there a way to save value of a meta when ‘context’ is set to ‘side’?

  127. Sidne

    Hi, sorry. I just used the same field name as metabox id so I can’t save them. Now it’s different, and can be saved.

    Unlimited Thanks! :)

  128. Luke

    +1 for Ross’s idea. I would definitely be willing to help out.

  129. Lukas

    Hi Dimas!

    Thanks heaps for your class! It’s brilliant and great pleasure to use!

    I found a minor bug though:
    Say we have a metabox in WPALCHEMY_MODE_ARRAY mode with a textfield. Now, we:
    1) insert some value to the textfield and save
    2) delete the value so the textfield is empty and save
    3) insert some value again and save

    After that the new value WOULDN’T BE SAVED!

    here are the critical lines in the code (lines 2018 – 2028 in version 1.3.11):

    $current_data = get_post_meta($post_id, $this->id, TRUE);
    if ($current_data)
    {
    if (is_null($new_data)) delete_post_meta($post_id,$this->id);
    else update_post_meta($post_id,$this->id,$new_data);
    }
    elseif (!is_null($new_data))
    {
    add_post_meta($post_id,$this->id,$new_data,TRUE);
    }
    

    and here is the solution:

    $current_data = get_post_meta($post_id, $this->id, TRUE);
    if ($current_data !== "") // when get_post_meta doesn't find anything, it returns empty string
    {
    if (empty($new_data)) delete_post_meta($post_id,$this->id); // we wan't to delete the current meta even when the new data are empty array
    else update_post_meta($post_id,$this->id,$new_data);
    }
    elseif (!empty($new_data))
    {
    add_post_meta($post_id,$this->id,$new_data,TRUE);
    }
    

    Actually if i think about it, using empty() is not the perfect solution either (see php docs of empty()), because we need to consider as empty only:

    1) null
    2) “” (empty string)
    3) empty array

    so that 0 and “0” are not considered as empty… so the best would probably be to write our own function my_empty() and use it.

  130. Lukas

    Great, thanks for the new version!
    As I said, it’s pleasure working with your code.

  131. Lukas

    Hey Dimas,

    I think I found another little bug:

    When you use multiple fields, it’s in the javascript function for adding new ones – starts on line 1288 in version 1.3.13. The problem is that if you use code like this:

    while($mb->have_fields_and_multi('product_options')):
    $mb->the_group_open('div');
    $mb->the_field('some_field');
    echo '<label for="' . $mb->the_name() . '">Some field:</label>';
    echo '<input type="text" id="' . $mb->the_name() . '" name="' . $mb->the_name() . '" value="' . $mb->the_value() . '"/>';
    $mb->the_group_close();
    endwhile;
    

    And you start adding new fields, the javascript wouldn’t increase the index in the ‘id’ and ‘for’ attributes – only in ‘name’ ones, which results in improper behaviour of labels when you click on them to gain focus on the textfields they’re attached to. moreover it causes duplicate ids.

    Here’s a quick fix, I’ve done – don’t have enough big picture to fix this issue properly but at least it gives you an idea what i mean. And so far it works properly – even when you use elements without ids.

    the_group.find('input, textarea, select, button').each(function(i,elem)
    {
    var the_name = $(elem).attr('name');
    if ('' != the_name)
    {
    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);
    }
    var the_id = $(elem).attr('id');
    if ('' != the_id)
    {
    var the_id_match = the_id.match(/\[(\d+)\]/i);
    the_id = the_id.replace(the_id_match[0],'['+(+the_id_match[1]+1)+']');
    $(elem).attr('id',the_id);
    }
    });
    the_group.find('label').each(function(i,elem)
    {
    var the_for = $(elem).attr('for');
    if ('' != the_for)
    {
    var the_for_match = the_for.match(/\[(\d+)\]/i);
    the_for = the_for.replace(the_for_match[0],'['+(+the_for_match[1]+1)+']');
    $(elem).attr('for',the_for);
    }
    });
    
  132. J Fishwick

    Excellent work here; I’ll just be throwing out the meta_box functions in all the themes I modify and using yours from here on out.

    Could you help me troubleshoot something? I’m pretty much following your example exactly for an endlessly repeating field, but the “Add” button isn’t actually replicating the field.

    Here is how I create the meta_box instance:

    $sidebar_images_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_sidebar_images_meta',
    'title' => 'Sidebar Images',
    'template' => TEMPLATEPATH . '/custom/sidebar_images_meta.php',
    'types' => array('page'),
    'exclude_template' => 'index.php',
    'priority' => 'high'
    ));

    Here is my template:

    <?php while($mb->have_fields_and_multi('sidebar_image')): ?>
    <?php $mb->the_group_open(); ?>
    <label>The Image Path</label>
    <p>
    <?php $mb->the_field('src'); ?>
    <input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/>
    <span>Using the "<em>Add an Image</em>" button, Upload an image and paste the URL here. Images will be resized automatically.</span>
    </p>
    <label>ALT Description <span>(optional)</span></label>
    <p>
    <?php $mb->the_field('alt'); ?>
    <textarea name="<?php $mb->the_name(); ?>" rows="3"><?php $mb->the_value(); ?></textarea>
    <span>Enter in an ALT description.</span>
    </p>
    </div>
    <?php $mb->the_group_close(); ?>
    <?php endwhile; ?>
    <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-sidebar_image button">Add Anoter Image</a></p>
    

    Again, just can’t get the field to replicate when clicking “Add Another Image.” Any ideas?

  133. Ryan

    Hi Dimas,

    First of all thanks so much for this Class! It’s helped massively so far.

    However I am having an issue. I’m trying to output some meta box content and a wrapper div only if the meta box content exists, this is what I’m having but it’s throwing back a fatal error:

    
    have_fields('description')) : ?>
    

    Any tips on what I’m doing wrong? I’ve read previous comments above and some of your other articles but I’m not having any luck.

  134. Ryan

    hmm that didn’t work, let me try again:

    if($secondaryContentmb->have_fields('description')) : ?>
    echo $secondaryContentmb['title'];?>
    echo $secondaryContentmb['description'];?>
    endif; ?>

    I had to remove all the opening php tags.

  135. Luke

    @J Fishwick – I’ve been using this same thing recently with great luck. I’ve tested your code and I got it to work (screenshot). I am using version 1.3.12 of the class, what version are you using? I would suggest down loading the current version.

    Also, I noticed you had an extra closing /div tag above your the_group_close(); ?> call. That may be causing some troubles too.

  136. Luke

    @Ryan – try using a while statement instead of an if

    while($secondaryContentmb->have_fields('description')) : ?>
    echo $secondaryContentmb['title'];?>
    echo $secondaryContentmb['description'];?>
    endif; ?>
    
  137. Ryan

    Thanks for the suggestion Luke, though I’m still getting an error: Fatal error: Call to a member function have_fields() on a non-object in /Users/………/wp-content/themes/sbb/page.php on line 22

    Line 22 is: while($secondaryContentmb->have_fields('description')) :

  138. J Fishwick

    @Luke

    Haha, of course it was just bad markup on my part… Thanks! FYI, your thread here has been invaluable, thanks for the good questions, code samples et al.

  139. Bryan

    Dimas,
    I’m applying the helper class to a custom post type, it seems to be storing the data appropriately (it’s there when I look at the database), but when I return to a custom post that has data saved on it, it doesn’t appear on the form and if I re-enter data, the old data is overwritten.

    I’m using while($mb->have_fields_and_multi(‘songs’)): to create the n-number-of-fields meta template…

    Am I missing something?

  140. Bryan

    …as a followup:

    I’m still having issues, but I *have* discovered that $mb->current_post_id seems to be 8, though the post in question is 9.

    I’m not 100% that this is not-as-designed, but it seemed odd to me and seems like it might cause the behavior I’m seeing.

    Thoughts?

  141. Bryan

    …. (Part III)

    Ok, I’ve found a solution. It seems that a separate query for some other custom fields was interfering with the $post’s context, thereby making the metabox use the wrong post for its data. I solved it by tossing the following code into the class (right at the top of the _meta function):

    function _meta($post_id = NULL, $internal = FALSE)
    {
    if ( ! is_numeric($post_id))
    {
    if ($internal AND $this->current_post_id)
    {
    $post_id = $this->current_post_id;
    }
    else
    {
    global $post;
    $p_post_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : '' ;
    $g_post_id = isset($_GET['post']) ? $_GET['post'] : '' ;
    $post_id = $g_post_id ? $g_post_id : $p_post_id ;
    $post = get_post($post_id);
    $post_id = $post->ID;
    }
    }

    // this allows multiple internal calls to _meta() without having to fetch data everytime

    Basically, it goes back to the get/post data to determine what the source post is… this may not cover 100% of the use cases, so I’m not suggesting that this solution become part of the codebase, but it solved my particular issue.

  142. Wesley

    Firstly, thanks Dimas. This is very cool :)

    I am having a small issue which I hope can be easily rectified (I’m pretty new to this so my php knowledge is somewhat lacking!).

    I’m using have_fields_and_multi(')) for links and link text but when I loop through it in my theme it never displays the first link/linktext entered. Here is my metabox code:

    Remove All
    Add links to external sites
    Important - you must add the full url (example: http://www.yourdomain.com)
    have_fields_and_multi('links')): ?>
    the_group_open(); ?>

    the_field('title'); ?>
    Link Text:<input type="text" name="the_name(); ?>" value="the_value(); ?>"/>

    the_field('url'); ?>
    Link URL:<input type="text" name="the_name(); ?>" value="the_value(); ?>"/>

    Remove Release
    the_group_close(); ?>

    Add Another Release


    and here is the code in my template file:

    have_fields('links')) : ?>
    Artist Links

    have_fields('links')) : ?>
    <a href=the_value('url'); ?> >the_value('title'); ?>

    Your helps much appreciated!

  143. Bryan

    Dimas,
    I just sent a pull request on github so you could have some context on what I did to fix the issue.

  144. Wesley

    Dimas

    Yeah sorry about that, it does look out of whack. Here is the post again as suggested:

    I am having a small issue which I hope can be easily rectified (I’m pretty new to this so my php knowledge is somewhat lacking!).

    I’m using ‘have_fields_and_multi(‘))’ for links and link text but when I loop through it in my theme it never displays the first link/linktext entered. Here is my code:

    https://gist.github.com/664345

    Thanks in advance

  145. Alan K

    Thanks for creating this man! This is such a lifesafer…

  146. Wesley

    Dimas

    I’ve tried the code but you suggested but it still doesn’t work. When I uncomment the print_r line it outputs ‘Array’ to the page. Other than that it is still acting the same.

    Any further ideas?

  147. Luke

    Wesley,

    Change your if statement to if($cm_links->get_the_value(('links')).

    This will check if there is a value ( get_the_value() ), if so, then the while loop will run, if not, it will pass.

  148. Wesley

    Hi Luke

    Thanks for the suggestion.

    That seems to crash the page and I just get a blank window. All the data entered in the admin is saved into the database, i’ve checked. It just seems the loop ignores the first set of data entered into the links meta box. The second link url/link text entered prints out as you’d expect. It’s weird!

  149. Bryan

    Wesley, Luke, and Dimas,
    Is it possible that Wesley is seeing the same thing that I was? It’s the same symptom at least. One of the first things that led me to my solution was that I did a print_r of $mb and saw that it was actually pulling the meta data from the wrong post.

    Wesley, do you have any other custom functions on the page that may be hijacking the current post context?

  150. Lukas

    Hi Dimas, any update about the javascript issue I wrote about in my last post, please?

  151. Luke

    @Wesley

    Here is the code snippet I used to test which works perfect.

    Here is a screenshot of it working on the first post, that has two links added (link 1, link 2) via WPAlechemy MetaBox have_fields_and_multi(). Artist title shows and both custom links are accounted for.

    Here is a screenshot of the next post in line that does not have links added. As you can see, the Artist Links title does not show nor do any custom links.

    I’ve been using the have_fields_and_multi() religiously in the latest theme I’m building. I did come across this situation before with the same result you had running the if statement with a while loop on the have_fields_and_multi(). It will produce the same result if you were to call $cm_links->the_meta() twice as well on the same page. I’m not sure why, just trial and error stuff I’ve concluded.

  152. Luke

    Sorry, used same link for second screenshot. Here it is without links showing.

  153. Bryan

    Dimas,
    The trick is that there was a non-metabox set of custom fields directly above the metabox that was querying ANOTHER custom post type and thus changing the context of the ‘current post.’

    Does that make sense?

  154. Bryan

    Dimas, that looks like the exact same problem. Seems like I missed it in searching the comment list.

  155. rZr

    The taxonomies of wordpress will be more and more important.

    I missed an easy way to show and use these in the current code. Especially the checklist (hierachial) lists.

    Please find below an easy to use piece of code to display an taxonomy (with selected options) as an checklist:


    'probleem');
    $taxonomy = array_pop(get_taxonomies( $args, 'objects'));
    ?>

    labels->name; ?><!--(optional)-->

    name, 'orderby=name&hide_empty=0');
    $post_terms = wp_get_post_terms( $mb->current_post_id, $taxonomy->name);
    $mb->the_field($taxonomy->name);
    ?>

    <li class="popular-category" id="name;?>">

    <input type="checkbox" name="the_name(); ?>" value="term_id; ?>"term_id, $post_terms); ?>>
    name; ?>

    <!--<select name="the_name(); ?>">

    <option value="term_id; ?>"the_select_state($term->term_id); ?>
    ' . $term->name; ?>

    -->

    Selecteer alle labels->name; ?>

    You would only have to adjust the first line of PHP code to get another taxonomy.

    Now I am trying to find an way to add an new taxonomy on the fly. Question: Is there an hook which I can use to custom save an added field?

    Thanks in advance for your sweet plugin– hope you can focus on Taxonomies a little bit ;).

  156. rZr

    The above post has been mangled a little bit. My apologies– maybe the host can adjust it a little bit.

    As an addition I would like to rephrase my next question: Is there an good solution to add an new taxonomy on the fly with the Metabox class?

    Looking forward to implementing that final piece of the puzzle.

  157. J Fishwick

    Any tips for using a meta box value to sort a query?

    I’m trying to use orderby=meta_value or orderby=meta_value_num in conjunction with an “Order” custom meta box. It is simply:

    <div class="my_meta_control">
    <label>Order</label>
    <p>
    <?php $mb->the_field('order'); ?>
    <input type="text" size="4" style="width:auto" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/>
    </p>
    </div>
    

    Not having much luck though.

  158. Wesley

    @luke

    That’s fantastic, your code worked a treat.

    Thanks so much,
    Wesley

  159. rZr

    And here is the code again: https://gist.github.com/666732

    Somehow the $mb tag was giving problems as an global so I passed it to the function (lame but it works for now) ;).

    Usage: checkbox_taxonomy(‘taxonomy’, $mb);

    Just type you taxonomy in the string field and the code will build an checkbox layout for you. The add button functionality is still not working. Saving it for later x).

  160. Lukas

    Hi Dimas, thanks a lot for the fix. It doesn’t work properly yet though. I don’t know javascript very well so i’m not sure i understand well what’s going on there but it seems like the code works only when the found elements have all the attributes (id, name, for) specified. if that’s not the case, it creates error that the_match is null.
    So i added a check on undefined for the_match as well (v 1.3.15, from line 1301):

    if (undefined != the_prop)
    {
    var the_match = the_prop.match(/\[(\d+)\]/i);
    if(undefined != the_match) {
    the_prop = the_prop.replace(the_match[0],'['+(+the_match[1]+1)+']');
    $(elem).attr(the_props[j], the_prop);
    }
    }
    

    and it works perfectly!

  161. rZr

    Sorry, something went wrong with the previous code?

    https://gist.github.com/667683

    I feel like I am pushing here. But I would love to hear your expectation of implementing Taxonomies ;). Even though the current code is sufficient for my needs now, it would be good for future users and myself to have it supported out of the box by the Metabox class.

  162. Ryan R

    Hello,

    I’m still stuck on this fatal error problem. Basically what I want to do is only show metabox content if it contains data, if the user has left the metabox blank then don’t show anything on the live page:

    https://gist.github.com/667689

  163. Ryan R

    Nevermind, I’ve used: if(!empty($secondaryContentmb['title'])) { ?>

    Thanks for the amazing class!

  164. rZr

    I have been thinking about it. And I would like to help implement the Taxonomies in your plugin (first basic functionality) if you wish.

    The experience and enthosiasm is here and so is the time ;). Would it be possible for you to contact me on my hotmail?

    I would love to show you my current backend of my custom posts with your plugin and custom metaboxes to explain where I am going.

  165. rZr

    I have managed to create the custom metabox which I wanted. Its fully functional and would like to share the screengrab of the Admin panel with you:

    http://imgur.com/agvNI.jpg

    @all: Let me know if you have any interest in the code or functionality.
    @dimas: Now the proof of concept has been finished this particular piece of code can be introduced in your plugin fairly easy. If you would like me to send you the access to the admin panel or something else, please let me know.

  166. rZr

    I can only agree with your points. Looking forward on working together on tackling Taxonomies in an easy to customize plugin.

    Note that I have tried all taxonomy managers out there so far. And I can tell that having the control by code is much more preferred. So I would like to focus on the metabox as of now.

  167. Carlos Takemura

    @rZr I like the screenshot with the columns of custom taxonomies and check boxes. I’m really interested in this for my project.

    Are you for hire?

  168. J Fishwick

    I’ve been using the class to great success on a demo version of a site. Today I am launching the site, and I migrated my WordPress site to the new domain. I ran some SQL statements to update URLS for images and such, as well as installing a database manager plug-in for the client.

    I then noticed that none of the meta data for my WPAlchemy boxes was in any of my posts or pages. What’s worse is that no new data I enter is saved. Everything was working perfectly before the migration. Anyone have any clues to why this is happening?!

  169. J FIshwick

    So, I had the site I’m working on in a subdomain, and now I’ve moved it to the root of the domain. I just moved the files, and I’m actually using the same database. What I’ve done since then is:

    1) Import a couple blog entries via import/export
    2) Ran these SQL statements:
    UPDATE wp_options SET option_value = replace(option_value, ‘http://subdomain.domain.com’, ‘http://www.domain.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
    UPDATE wp_posts SET guid = replace(guid, ‘http://subdomain.domain.com’,’http://www.domain.com’);
    UPDATE wp_posts SET post_content = replace(post_content, ‘http://subdomain.domain.com’, ‘http://www.domain.com’);
    3) Installed the WP-DBManager plugin.

    Is there a way I can confirm or deny your hypothesis?

  170. J Fishwick

    BTW Dimas, I’m fine with nuking the old data, I just need a way to be able to save again.

  171. J Fishwick

    Thanks Dimas.

    I was able to properly serialize my the table holding my post metadata and all is well.

  172. Benj

    Hi Dimas, thanks for all your hard work on this code, it’s really made my recent batch of wordpress projects really sing.

    I’m doing something a little more knotty with it now though and having some trouble trying to handle query_posts. I have a meta box with a have_fields_and_multi. I want to filter query_posts by one of the multi-field values and I can’t work out how to do it.

    So a post may have multiple dates assigned to it and I want to be able filter the query against a particular date. So let’s say that the field within the multi in question is called event_date and on the current post it has 3 date entries, others might have 1 and some may have 6-8.

    event_date:
    0 -> 1290470400,
    1 -> 1292198400,
    2 -> 1292371200

    I want to be able to run a query to check if posts appear on a single date. Is there a way to do it? Cheers for your assistance.

  173. Josh Byers

    Dimas, once again, thank you for the wonderful work you have done and for the support you have generously given.

    I was able to get the taxonomy issue worked out with the post from NetConstructor and it is functioning like a champ.

    I have one issue that has come up that I was hoping you could help with.

    I have a need for users to import posts from a csv file. I’m using the CSV Importer plugin. When the csv data is imported the custom field data is imported and is displayed in custom fields UI, but the meta boxes I created using your class are not populated with the custom field data.

    When I create a post manually and input the data in the custom meta box fields it also populates the default custom fields ui.

    Is this possible for the import to also populate the custom meta fields?

  174. Benj

    Thanks Dimas,
    Understood completely, your a genius. Got it working this morning and it works a treat. Now I can do queries based on groups of entries like event dates, etc.

    For anyone else that wants to search by a group (array) of meta data this is how I did it, based on your advice:

    So to make query safe arrays from metabox groups:

    1. Add the following line to your custom meta box and make a nice name for your custom save function:
    ‘save_filter’ => ‘my_save_filter_func’

    e.g. :

    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'template' => TEMPLATEPATH . '/custom/meta.php'
    'save_filter' => 'my_save_filter_func'
    ));
    

    2. Make a function to duplicate your existing meta box data into a query safe version:

    function my_save_filter_func($meta, $post_id)
    {
    //The name of the new key (to be used in queries)
    $meta_key = '_safe_example';
    //Clear out existing entries
    delete_post_meta($post_id, $meta_key);
    //Loop through the field group and save the group values to a new custom field with a non unique name
    foreach($meta['example_group'] as $item) {
    add_post_meta($post_id, $meta_key, $item['example_field'], false);
    }
    }
    

    Note: If you have additional data (in $meta) that needs to be saved by wpalchemy, your my_save_filter_func() should end with return $meta;.

    3. Have fun making queries that target a specific meta value:

    query_posts('meta_key=_safe_example&meta_value=example_value');
    
  175. Josh Byers

    Dimas,

    I used the WordPress CSV Importer.

    http://wordpress.org/extend/plugins/csv-importer/

    To replicate, yes I would set up normal fields and then try and import data into them via custom fields.

    I’m using 6 meta boxes in my custom post type but the code below is my typical set-up.

    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => 'custom_meta', // underscore prefix hides fields from the custom fields area
    'title' => 'Basic Information',
    'template' => TEMPLATEPATH . '/includes/meta/basic_information.php',
    'types' => array('student'), // added only for custom post type "student"
    'mode' => WPALCHEMY_MODE_EXTRACT,
    'prefix' => 'ymdb_',
    'save_action' => 'save_basic_taxonomy_terms'
    ));
    function save_basic_taxonomy_terms($meta, $post_id)
    {
    wp_set_post_terms($post_id, array($meta['my_terms']), 'ministry-groups', FALSE);
    wp_set_post_terms($post_id, array($meta['my_terms2']), 'school', FALSE);
    }
    
  176. rZr

    I just wanted to show you guys that I finished my file uploader which uses the WP lightbox media library and retrieves the file from it.

    screenshot

  177. Elaine

    Dimas,

    I seem to be having trouble actually fetching the data from the database and display in both the backend and frontend. It was actually working for me, but I have tried to migrate over to a new server and suddenly the data is not being displayed. Any idea why this is? Do you think there are certain server-related settings I have to set in order for it to work?

    The function is initializing because the meta boxes are being displayed in the backend. But once it actually tries to fetch the data it is giving an invalid argument supplied error.

    Help please? :)

  178. Elaine

    Figures that I would manage to solve this after 5 minutes of posting the comment haha! It was actually a really silly mistake on my part when declaring the ID in funcations.php file. Strange that my own server was not complaining and it worked fine even with the mistake!!

    Thanks heaps for this, I love using this custom class :)

  179. shag

    Howdy. First off, I love this thing. Very impressive indeed. I’ve got it working great on single pages but when I try to display some data in a custom loop on a non-single page, I have no luck. I’m using query_post in coordination with some info from your Storage Modes post.


    query_posts( array( 'post_type' => 'client_horses', 'order' => 'asc', 'post__in' => $horse_var, 'meta_key' => $client_horse_news_metabox->get_the_name('client-horse-news') ) );

    I get nothing when using this, which works on the single page:

    $client_horse_news_metabox->the_value('news-date');

    I’ve also tried various other approaches including:

    echo get_post_meta(get_the_ID(),$client_horse_news_metabox->get_the_value('news-date'),TRUE);

    This last approach spits out the word “Array” and when I var_dump that array, it has all of the correct data so it’s there but it’s not wanting to show itself for me using anything I’ve tried.

    Any thoughts? Thanks

  180. shag

    Actually, I’ve made a bit of progress (like the poster above, 5 minutes after I posted!) I toyed with the prefix setting a bit and it started working.

    I now get the values within the loop using:


    while($client_horse_news_metabox->have_fields('client-horse-news')) { ?>
    the_value('_my_news-date'); ?> - the_value('_my_news-info'); ?>

    The issue now is that the WP loop is only grabbing the meta data from the first post in the loop. So if there’s 4 posts (not meta entries), it displays the custom meta from the first post 4 times. The WP loop correctly grabs the 4 different post titles but not the correct custom meta data. Is there a reset function that I missed perhaps?
    Thanks

  181. Ross

    Dimas,

    Any possibility of an include/exclude option for post parent IDs?

    -Ross

  182. Kathy

    Hi Dimas, have you tested this with any of the WordPress 3.1 beta builds? I just installed 3.1 to get a look at the custom post type archives feature and now none of my previously functioning boxes will save their data. Also- I wanted to echo what another poster said, you should put up a tip jar.

  183. Hank

    Can someone share the code that must be added to allow image uploading with this script?

  184. rzr

    @hank:

    I have finished my file uploader just recently, which incorporates the WP media uploader. Check out the screenshot somewhere in this thread.

    We hope to have an tutorial on this blog shortly.

  185. Kathy

    No import/export. Right now I couldn’t tell you what happened and it didn’t seem consistently broken- 3.1 locally worked, but 3.1 live didn’t? It was really random and the type of useless “it doesn’t work” message that I hate getting from my family when stuff goes wrong. :) I’ve been totally swamped lately, but was going to eventually try to isolate the problem. Glad to hear it is working for you and I will upgrade to the newest version and let you know.

    sidenote- is there a way to add your metaboxes to a category page? Not a post in a specific category, but rather the category info/description page? like this:

    http://www.strangework.com/2010/07/01/how-to-save-taxonomy-meta-data-as-an-options-array-in-wordpress/

    @rzr – I can’t wait to see the uploader! Sounds awesome.

  186. Kathy

    I read some of the comments on saving safe query data and I thought I’d post how I did it in regular mode.

    here is a screenshot of what I made:
    http://www.flickr.com/photos/29025521@N02/5249101836/

    and here is all 3 parts of the code, the metabox definition, the html, and the modification to the query

    http://pastebin.com/3fq42bjg

    I’d love to move this to a more graphical/intuitive setup, as right now it works but I think only established WP users/developers would feel comfortable with manually entering the query params.

  187. Kathy

    sounds like it will be great Dimas! I look forward to using it.

  188. Sidne

    @rZr
    I can’t wait to see file uploader! It must be cool!

  189. Hank Pantier

    Wondering if any progress had been made on limiting the number of adds for group elements. I am using your class to build out a backend where a client can upload logos – to work in the template, I’d like to limit that to 5.

    Basically the same question that “Tyler” asked on August 3, 2010 at 2:53 pm…

    Thank you for your help and for this fantastic class.

  190. Hank

    @Dimas – that would be fantastic…thank you!

  191. Hank Pantier

    I am trying to change the values in the columns for my custom post type. The code i am using is below, I keep getting the following error message Fatal error: Call to a member function the_meta() on a non-object in – anyone know how to solve this?

    This is all being called from my functions.php file i am including MetaBox.php at the beginning of it.

    function campaign_fundraising_custom_columns($column){
    global $wpdb;
    switch ($column){
    case "snippet":
    global $custom_metabox_snippet;
    $meta = $custom_metabox_snippet->the_meta();
    echo '<pre>';
    print_r($meta);
    echo '</pre>';
    break;
    case "price":
    ........... etc ...........
    }
    }
    

    Thanks in advance for your help.

  192. Hank

    i ended up solving my own “issue” – hope this helps someone else out.

    function my_custom_columns($column){
    global $wpdb;
    $custom = get_post_custom();
    switch ($column){
    case "snippet":			
    echo $custom['value'][0];
    break;
    ...... etc ......
    }
    }
    

    @Dimas any progress on limiting the number of new fields you can add?

  193. Hank

    @Dimas – thank you for this – heading over to git so i can start implementing this now.

  194. Hank

    @Dimas – the new ‘length’ parameter seems to work just fine – but the limit parameter doesn’t ever seem to shut the ‘add more’ button off…

  195. Matt

    Is it possible to pull all data from the metaboxes from every post/page?

    For example let’s say you had metabox data on every post but you wanted to pull all the data from every metabox from every post and display it on the homepage, is that possible?

    I know you can pull all the custom-field data with something like this;
    post->ID;
    echo get_post_meta($postid, 'customField', true);
    ?>

    But i’m not sure how you would do it with the custom metaboxes?

    Thanks.

  196. Matt

    Thanks.

    So to get the values I would do something like this?


    global $custom_metabox, $post;
    $myQuery = new WP_Query('category_name=featuerd');

    while ($myQuery->have_posts())
    {
    $myQuery->the_post();

    $meta = get_post_meta($post->ID, '_custom_meta', true);

    // print "

    \n";
    // print_r($meta);
    // print "

    \n";
    }

    while ($custom_metabox->have_fields_and_multi('docs')):

    // echo out values.

    endwhile;

    or am I way off track here?

  197. Jonathan Wold

    WPAlchemy has been very helpful and I appreciate all the work you’ve put into it! I’ve used it successfully so far to add some select menus for custom taxonomies.

    My last stop is a checkbox list for a custom taxonomy, allowing multiple selections. I’ve followed the thread above and I’ve gotten close. At one point, I broke off and tried to apply the WP Taxonomy class referenced above, in development on Github. While my PHP ability is increasing fast, it’s not quite there yet :).

    The problem I’ve run into is saving. The closest I got was a list of custom taxonomies, iterating out with checkboxes (this was before I attempted the WP Taxonomy class). When I would check two or more, only one would save.

    Any updates on best practice or a reference to a working example? Any ideas or suggestions are appreciated. Thank you!

  198. Jonathan Wold

    For reference, here’s the code I’m using to call the box and then the code I’m using to display the template:

    https://gist.github.com/752300

    It displays the list of “presenters” and, when you check multiple and update, it makes the update, but for only one.

  199. Matt

    Yeah, got it working.

    Thanks Dimas.

  200. Matt

    One other thing actually. How would I go about making the $custom_metabox type array accept some variables from a function?

    For example;

     
    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'template' => TEMPLATEPATH . '/custom/meta.php',
    'types' => array('post',$type,'page'), 
    ));
    function postType($type){
    $type = "type_name";
    return $type;
    }
    

    Thanks

  201. Justin Myers

    One quick question. I didn’t see this feature anywhere so I may be blind, but is there a way to have a default value with a field?

    This way if the field is not already populated it will show up with a default value for the user. I added some code to the class to do this and basically I envisioned it as:

    $metabox->the_value('var', 'defaultValue');

    Does this already exist in WPAlchemy and if not are you planning on adding it?

  202. Roy

    Hi

    Thanks for this class, it’s awesome. I do have a question though, I tried creating a new metabox in a function that gets called on a admin_init hook but that won’t work.

    It only works when put directly in the functions.php file and I’ve been reading that’s not best practice.

    Does anyone know what im doing wrong here?

    Thanks

  203. caratage

    Hi all,

    I am following your conversation for a while now after installing gorgeous WPAlchemy. Thanks, Dimas, for all your work and sharing! I helped my a lot on my current work and I got really inspired of how I could use it in further projects.

    @rzr: Do you have news about your image/file uploader? This seems interesting..

    Cheers

  204. Michelle

    Hi Dimas,
    First thank you so much for the fantastic code! I feel *so close* to getting it working but I’m not there yet. :)

    I’m running this on localhost, if that makes a difference, running WP 3.1 RC2, and I’m getting this error when trying to load my edit-page page to see the meta boxes:

    Fatal error: Call to undefined function add_action() in C:\xampp\htdocs\texaspbs\wp\wp-content\themes\texaspbs-toolbox\WPAlchemy\MetaBox.php on line 16

    Fatal error: Class 'WPAlchemy_MetaBox' not found in C:\xampp\htdocs\texaspbs\wp\wp-content\themes\texaspbs-toolbox\functions.php on line 260

    My meta.php is copied directly from your example code above. Here is what I have in my Functions.php:

    /**
    * WP ALCHEMY META BOX SETUP
    */
    // include the class in your theme or plugin
    include_once get_template_directory_uri(). '/WPAlchemy/MetaBox.php';
    // include css to help style our custom meta boxes
    if (is_admin()) wp_enqueue_style('custom_meta_css',get_template_directory_uri() . '/custom/meta.css');
    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => 'txpbs_station_information',
    'title' => 'Station Information',
    'template' => get_template_directory_uri() . '/custom/meta.php',
    'types' => array('post','page','txpbs_stations'),
    //'context' => 'side',
    //'mode' => WPALCHEMY_MODE_EXTRACT,
    //'prefix' => '_si_',
    'include_template' => 'stations.php',
    //'init_action' => 'my_init_action_func',
    'view' => WPALCHEMY_VIEW_ALWAYS_OPENED,
    ));
    

    Any ideas on what I’m doing wrong? Thanks so much for your help!!

    Michelle

  205. Michelle

    Hooray! Thank you Dimas! That was indeed it. I needed to update the paths for both the class and the template. Here’s the updated, functional code – hope it helps someone:

    /**
    * WP ALCHEMY META BOX SETUP
    */
    // include the class in your theme or plugin
    include_once get_stylesheet_directory(). '/WPAlchemy/MetaBox.php';
    // include css to help style our custom meta boxes
    if (is_admin()) wp_enqueue_style('custom_meta_css',get_template_directory_uri() . '/custom/meta.css');
    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => 'txpbs_station_information',
    'title' => 'Station Information',
    'template' => get_stylesheet_directory(). '/custom/meta.php',
    'types' => array('post','page','txpbs_stations'),
    //'context' => 'side',
    //'mode' => WPALCHEMY_MODE_EXTRACT,
    //'prefix' => '_si_',
    'include_template' => 'stations.php',
    //'init_action' => 'my_init_action_func',
    'view' => WPALCHEMY_VIEW_ALWAYS_OPENED
    ));
    
  206. Michelle

    In case it helps anyone, here’s how to add an ‘image upload’ metabox to this script. I found and modified the code from this page (and others – it was yesterday so I can’t remember them all but if you helped, thank you!): http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/

    I’m having trouble getting the code to display correctly in these comments so I’ve put it all in pastebin.

    Copy this into a new file called img-upload.js and save it in your theme’s /custom/ folder:
    http://pastebin.com/iS4KpAPW

    Add this to your functions.php: http://pastebin.com/H3sN3RfS

    Add this to your template file (meta.php or whatever you’re using):
    http://pastebin.com/QrUE4grc

    And to display the image, use this in your theme template files:
    http://pastebin.com/heELkcez

    Hope this helps someone!
    Michelle

  207. Leland

    @rZr

    Can you share your media upload code extension. That would be great. Thank you.

  208. rzr

    @Leland, and others: thanks for the cry outs, I really want to share it asap. I have expanded on its functionality and it will blow you away.

    Now to find some time to write the tutorial on the WPAlchemy blog. I will try to free some time this weekend because I am swamped. :(

    Also wrote an WP 3.1 extension for choosing post IDs by using the WP core. Sweet stuff!

  209. Leland

    @rzr

    Any chance you could pastbin or email your code with basic instructions so I could at least give it a try and provide feedback? I am getting ready to release a new theme that would greatly benefit from this feature. I am relatively savvy with this stuff just not with media upload. Thank you.

  210. rzr

    @leland: I have just made an small simple example archive for Dimas (author of WPAlchemy) for review. After feedback I will contact you (if Dimas can be so kind to forward your email :).

  211. Chris

    @rzr: count me in on that code… I am very interested in how this might be accomplished in a clean way.

  212. Roy

    @rzr

    Me Three! :)

  213. Michelle

    Hi, really dumb question here… how do I include the meta boxes I’ve created using WPAlchemy in a custom post type? I have read up in the codex on how to register a post type, but I can’t figure out where in that function I call in WPAlchemy. (Or am I coming at this from the wrong direction altogether?)

    I won’t bother repasting the code I have now as it’s copied directly from http://codex.wordpress.org/Function_Reference/register_post_type :-)

    Thanks so much for your help!

  214. kathy

    @michelle- i asked that question a bunch of comments up and here was Dimas’ answer. you don’t enable WPAlchemy in the declaration of the post type. you enable it when you define your meta box.
    http://farinspace.com/wpalchemy-metabox/#comment-4682

    @rzr- can’t wait to see what you’ve done w/ the media uploader!

  215. Michelle

    @kathy, thank you! I think I’ve got it – I had tried that but my box wasn’t showing up due to also using include_template. Took that off and the boxes appear on my custom post just fine.

  216. Michelle

    Hi and thanks (again!) in advance for any help. :)

    I have everything working for a set of metaboxes which only appear when a page is set to use an “Agreements” page template. One of the metaboxes contains a list of “offices” checkboxes. Each item in the list is actually a link with a title, display name, and URL.

    What I’d like to do is allow the end-users to add to that list of checkboxes and have their additions be available to other users on other pages using the “Agreements” template.

    So, I set up a new instance of WPAlchemy and a new meta/page template called “Offices”. Now users can edit the Page called “Offices” and add new offices, designating their display name, title, and URL.

    What I’m having trouble with is pulling those values into the “Agreements” meta template.

    Hope that made some kind of sense!

    Here’s how I’ve declared my two WPAlchemy instances:

    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => 'utoie_agreement_info',
    'title' => 'Agreement Information',
    'template' => get_stylesheet_directory(). '/custom/meta-agreements.php',
    'types' => array('post','page'),
    'include_template' => 'agreement.php',
    'hide_editor' => TRUE,
    'view' => WPALCHEMY_VIEW_ALWAYS_OPENED
    ));
    $custom_office_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => 'utoie_office_information',
    'title' => 'Office Information',
    'template' => get_stylesheet_directory(). '/custom/meta-offices.php',
    'types' => array('post','page'),
    'hide_editor' => TRUE,
    'include_template' => 'offices.php',
    'view' => WPALCHEMY_VIEW_ALWAYS_OPENED
    ));
    

    Here’s my meta-office.php (linking off because I can’t figure out how to show php+html in these comments, sorry):
    http://friendly.pastebin.com/1FHVuJ4R

    Here’s my meta-agreements.php – see lines 11-18:
    http://friendly.pastebin.com/QbQcf52v

    Did I go about this entirely the wrong way? Thanks so much for your help!!

  217. Michelle

    Small correction to meta-agreements.php (I’d renamed the fields and forgot to update everywhere): http://friendly.pastebin.com/gNq6cUxu

  218. Michelle

    Small correction to meta-agreements.php (I’d renamed some fields and forgot to update them everywhere): http://friendly.pastebin.com/gNq6cUxu

  219. Michelle

    Thanks so much, Dimas!!

    I like the second suggestion, but for this site I think I have to use the first. (Each “Agreement” may have several ‘offices’ associated with it, and I have to display the list of Agreements and associated Offices in a huge table. There will likely be under 20 offices total; I just prefer not to hard-code the arrays of office data in the templates in case my clients ever want to add more.)

    I’m trying to get the first suggestion to work and here’s where I’m at – It displays the office data great in the Agreements metabox, but the checkboxes aren’t saving when I update the page. Here’s what I have in my meta-agreements.php – I didn’t change anything else:

    http://friendly.pastebin.com/fGS1n8Lk

    Any suggestions? Thanks again for your help and your FANTASTIC code!!

  220. Leland

    @Dimas

    Any updates with the RZR media upload extension? Thank you.

  221. Claudio

    @rzr
    I’m as well interested in the implementation of the media upload feature for WPAlchemy. I would like to have a look at your source code for my inspiration. I’m currently customizing a metabox for a university project. The custom_field_template isn’t a nice alternative.

    Thanks a lot!
    der/dot\herr/dot\c/at\googlemail/dot\com

  222. Elaine

    I am getting the following error when trying to access the meta values from loop-tag.php

    Fatal error: Call to a member function the_meta() on a non-object

    Any help on this would be much appreciated. Thanks!

  223. Andy H

    Hello,

    I was wondering the same thing as Ross above. How to write some conditional logic for a field.

    In English:
    Get the field
    Check if it’s empty
    If not, display the the value
    else echo “field not specified”

    Really, really nice work you have here ^__^ Thanks!

  224. Claudio

    @Andy H

    Are you looking for something like the following?

    // get the meta data for the current post
    $custom_metabox->the_meta();
    // set current field, then get value
    $custom_metabox->the_field('name');
    // check if 'the_value' is not empty
    if(!empty($custom_metabox->get_the_value())) {
    echo $custom_metabox->get_the_value();
    } else {
    echo 'field not specified';
    }
    
  225. Andy H

    Something seems to be wrong with it.

    It does not like the get_the_value() on this line:

    if(!empty($custom_metabox->get_the_value()))

    Big thank you!

  226. Luke

    @Dimas,

    I mentioned awhile back about possibly having the ability to sort have_fields_and_multi() items. I’ve gotten this working with the drag and drop action applied if your interested. I’m not sure about the best/easiest way of implementing it into your class though.

  227. Philip

    Dimas,

    Excellent work here–the class has saved me a lot of time and added valuable functionality to many of my clients’ sites.

    I also have a question regarding using WP Alchemy in WordPress posts. I have used metaboxes many many times in pages, but now I am trying to use them in posts and I am having trouble. I have a metabox set up as follows:

    $postType_metabox = new WPAlchemy_MetaBox(array
    (
    'id' =>  'postType_meta',
    'title' =>  'Post Type',
    'template' =>  TEMPLATEPATH . '/metaboxes/postType_meta.php',
    'types' =>  array('post'),
    ));
    

    When I try to reference the data using the_value('test') in the loop.php file, the page breaks at that point (no further output). I have tested the same reference on a page and it works just fine. I am a beginner at PHP, so I’m sure I’m just missing something obvious here…

    I’d really appreciate your help!

    Philip

  228. Luke

    @Phillip, have you tried adding global $postType_metabox; to your loop.php page?

  229. Luke

    I’m have a set of checkboxes in my metabox and I am trying to pull in the values of the checkboxes into my template. When I do, all I’m getting is the first character of the checked boxes value.

    For example, if I had check boxes checked for “Web”, “Print”, and “Logo”, I would only be getting “W”, “P”, and “L” to show on my page.

    while ( $custom_metabox->have_fields( 'services' ) ) : 
    echo $custom_metabox->the_value( 'services' ); 
    endwhile;
    
  230. Philip

    @Luke,

    Thanks! It works! But…why does it work? Was loop.php trying to reference the data before the object was created in the function.php file?

  231. Luke

    @Dimas, I may not have explained my problem correctly. I have the metabox working fine. It’s when I try pulling the values into my page template, for example page.php. It’s only displaying the first character of the checked boxes.

    Example Screenshot

    Maybe I’m overlooking something in the checkbox_meta.php you suggested?

  232. Michelle

    Hi Dimas,

    I’ve tried every combo of code I could think of using meta_checkboxes as a template, but I can’t seem to get the checkboxes populating and then the values saved into a different array no matter what I try. See my original comment and code from http://farinspace.com/wpalchemy-metabox/#comment-8513.

    I have one metabox group, “Offices”, where users can add Office Name, URL, etc.

    In the Agreements metabox, the Offices users added are displayed in a checkbox list, so users can check off the offices that pertain to that Agreement.

    The code above displays the Office list fine in the Agreement metabox, but the checkmarks aren’t saving on Update.

    Thank you so much for your help!!!

    Michelle

  233. Luke

    @Dimas, worked great. Seemed to easy… I should have probably been able to figure that one out 😉 Thanks!

  234. Claudio

    … any news concerning the Media Upload feature? Need it these days.

  235. Alex

    +1 on media upload as well as drag and drop (sortable) fields and field groups 😀

    The “Attachments” plugin offers drag and drop capability in case a code example is welcome. It’s the same code that was used for the “Simple Fields” plugin (per the “Simple Fields” change log).

    @Dimas – I’ve been watching WPAlchemy progress since last September… very impressive work and your efforts are MUCH appreciated!

    @Everyone else – your participation on this thread has been fanatastic and I appreciate your efforts as well!

  236. Leland

    @Dimas,

    +1 on the upload
    +1 drag and drop ordering of meta boxes or groups

    Any updates?

  237. Philip

    Dimas,

    Turns out calling the global variable doesn’t solve what I am trying to do–only one value is stored, meaning that even if I have different values held in each different post on the page (referenced via $postType_metabox->the_value('type');, for instance), the last metabox value will show up in each case…which makes sense since they are all being called with the same reference.

    Any idea how to get around this?

  238. Philip

    Figured it out! Just stored the post id in a variable and changed the reference on the front and back ends to:

    $postType_metabox->the_value("type$thisID")

  239. Roy

    @rzr

    Saw in your screenshot you are a dutchie. Where do you live so I can come give you a hug when that Media Uploader thing is available. :)

  240. Andy H

    Hello,

    I have trouble to get two set of fields working. I try to do it the way mentioned here http://farinspace.com/wordpress-meta-box-next-level/

    This is the code:

    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_custom_meta',
    'title' => 'Release info',
    'template' => TEMPLATEPATH . '/assets/select_meta.php',
    'types' => array('releases'),
    'priority' => 'high',
    'lock' => WPALCHEMY_LOCK_TOP // defaults to NULL
    ));
    //second set
    new WPAlchemy_MetaBox(array
    (
    'id' => '_custom_meta_artists',
    'title' => 'Artist info',
    'template' => TEMPLATEPATH . '/assets/artist_meta.php',
    'types' => array('artists'),
    'priority' => 'high',
    'lock' => WPALCHEMY_LOCK_TOP // defaults to NULL
    ));
    

    The problem is that I can’t pull the values from the second set of fields. If I put the $custom_metabox also in the front of the second set, I can pull the values, but then the first set breaks down. I’m running 3.1 RC3.

    Help is much appreciated :)

  241. Chris

    Hi guys

    This class is great. Very helpful.

    I was having problems with the_select_state() in my code. It was rendering the selected=”selected” part outside of my option tags.

    So I changed line 1784 of the MetaBox.php file to read ‘return’ instead of ‘echo’. And this seemed to work.

    I’m not entirely sure it’s a bug, because it might be my code that’s causing this workaround, but I thought I’d raise it.

    Cheers
    Chris

  242. kathy

    just echoing leland on the media uploader and drag and drop sorting. also, how is the taxonomy class coming along?

  243. kathy

    i posted this issue at github, but perhaps one of the other users has come across it when using the have_fields_and_multi function. i’m using the latest dev version (i also tried the 1.4.1 tagged version) and get the following error:

    Uncaught TypeError: Cannot read property ‘1’ of null

    which applies to the var the_limit declaration in the checkLoopLimit function


    function checkLoopLimit(name)
    {
    var elem = $('.docopy-' + name);

    var the_limit = $('.wpa_loop-' + name).attr('class').match(/wpa_loop_limit-([0-9]*)/i)[1];

    if ($('.wpa_group-' + name).not('.wpa_group.tocopy').length >= the_limit)
    {
    elem.hide();
    }
    else
    {
    elem.show();
    }
    }

    seems to be looking for a class wpa_loop_limit that isn’t in the markup, so the_limit is coming back undefined and breaking stuff.

    also regardless of how i set the limit $this->_loop_data->limit seems to come back as unset.

    tried both:
    $mb->have_fields_and_multi(‘docs’,5)
    and
    $mb->have_fields_and_multi(‘docs’,array(‘length’=>5))

    if there is no limit, then it seems like it shouldn’t call the checkLoopLimit function. and if there is a limit then it doesn’t seem to be picking it up.

    Not having the clearest of days so hopefully I am just missing something obvious.

  244. Joe

    I am trying to WP Query custom posts to use inside of a dropdown/select box using WP Alchemy, does anyone have any tips?

    I would like for the options to display the postname, but their value be the Post ID.

    Any clues?

  245. kathy

    thanks Dimas! In the end I adjusted how I was going to proceed and took a different route. Coming back to the multi groups again, but I don’t need the limit for the moment. But pertaining to multis with radios (and radios in general), is there a way to set a ‘default’ value? seems to me that radios are supposed to have something selected at all times. i’ve sort of managed this:


    $mb->the_field('r_ex3_r');

    if ( (NULL == $mb->get_the_value()) && ($i=='x')){ $default = ' checked="checked"';} ?>

    and then echoing the $default variable in the input i wish to designate as default.


    <input type="radio" name="the_name(); ?>" value="x"the_radio_state('x'); echo $default;?>/> x

    the code tags aren’t preserving my code right (switching php on/off) but I hope you get my point. however, I think it would be more elegant if the default could be a second parameter in the_field, like this maybe?


    $mb->the_field('r_ex3_r','x');

    or maybe better still as a parameter in the_radio_state. just marking the default value with a second parameter of true

    $mb->the_radio_state('x',true);

  246. Joe

    Got everything working perfectly, thanks to the help of some of you here!

    Luke, i’m interested in your sorting concept- as I’ve applied this: http://quasipartikel.at/multiselect_next/

    to a multiple select box and need for the saved selections to sort by the order they were dragged.

  247. Leland

    @Dimas

    Any idea when you will have time to implement the uploader and drag/drop sorting of fields or groups? I would be happy to make a donation for this dev to speed things up if that would help. Or assist in this coding? Thanks – these two features are the final missing features to make your framework a leader on the web. After Attending WordCamp Phoenix AZ 2011 I can say most devs have no idea how to manage these features in themes. Good work.

  248. Kathy

    ok alchemists- i’ve been one of the ones clamoring for the media uploader and had been holding off on doing it myself. it may not be as elegant as what is coming down the pipe from @rxr but if you need it now, try this out:

    to see what we’re going to attempt:
    http://img43.imageshack.us/img43/2867/metabox.png

    it is a repeating group that should hold an image, a text input and a text area.

    this is the bit that defines the boxes in my functions.php :

    http://pastebin.com/bMtLC0Rj

    this is the template for the metabox – new_featured_meta.php :
    http://pastebin.com/w0EeTwNi
    you should note that in my functions file i identify the template as:

    'template' => FUNCTIONS_PATH .'WPAlchemy/new_featured_meta.php',

    so i have the template in a folder called WPAlchemy inside a folder called functions

    my setup looks like this

    functions/WPAlchemy/new_featured_meta.php
    functions/WPAlchemy/MetaBox.php
    functions/WPAlchemy/meta.css
    functions.php

    and finally a bit o’ style- meta.css :
    http://pastebin.com/uBMaL4VS

    i spent the last day on it and so I hope that helps someone else. i’d also love to hear thoughts on using the WP uploader versus an script like Ajaxupload.

  249. Leland

    @Dimas

    If possible hooking into the WP media uploader would allow users to grab files that have already been uploaded or from other activated galleries such as the nextgen gallery (which loads in that window) that a TON of people use for multimedia management.

    The WP uploader isnt the best but it would make sure not to duplicate uploads etc

    Just my two cents,

    Thanks

  250. kathy

    Thanks Dimas. What was funny was that today as I was googling around for help on the solution to dealing w/ the media uploader i actually uncovered my own question on stackoverflow from 5 months ago. I guess i never figured it out then as I realized my old solution was flawed, but it seems clearer now, so i hope that it works as expected.

    Regarding WP Upload versus my own upload, Well I was thinking something similar to @Leland.

    The upside of hooking into the WP uploader is that is 1. familiar, and 2. lets the user select images that have already been uploaded somewhere.

    The downside is that it is 1. clunky, 2. presents an extra step and presents the possibility of the user inserting a thumbnail when you need the full version. I supposed that last part could be solved w/ some preg matching in a save filter? Haven’t gotten that far into it yet. Spent some time today with regex and still believe it is voodoo. Ended up not using it.

    I am using AjaxUpload in my theme options for a logo and background image, and it is definitely easier, but there is no way to access previously uploaded stuff.

    I can’t wait to see these other parts of WP_Alchemy!

  251. Joe

    With the WP Media Uploader option everyone is talking about, will it be possible to replicate WordPress’s “The Post Thumbnail” for images that are uploaded?

    Having the thumbnail that is clickable to show the larger version?

  252. pixenjoy

    Hello,

    Very good job Dimas, thank you for this great Classe.

    I’m just waiting for the Media Uploader now, i think it could be useful for everybody (me included)

    @rzr if you hear us 😉

  253. Luke

    I’ve been trying to find a way to create a dropdown of pages similiar to wp_dropdown_pages(), but inside of a have_fields_and_multi() loop. The problem I’m running into is each time I update the page, another group is added to the have_fields_and_multi() set.

    Here is an example of the code in use. This involves a foreach loop inside the while loop. My guess is this is not “allowed”, but it seems like I’m close.

    Thanks, in advance for any ideas!

  254. Leland

    @Dimas,

    Any idea about when you will have a chance to finish the 1.4 branch? Just so we stop pestering your comment board :)

    Thanks

  255. Theo Ribeiro

    Hi Dimas,

    Awesome code, I’m starting to implement it in a big project I’m just starting…

    One question I still couldn’t solve… How do you search within the newly created metaboxes?

    Can you perform a search only within a specified field?

    I’m trying a different approach on the TinyMCE implementation and when I get it working right I’ll post it here, so far it’s great with visual/html and image upload, etc… but has a little bug I’m trying to solve :)

    Also, I used a different aproach for conditionally displaying a field within a theme-template’s loop:

    $key = $custom_metabox->get_the_value('_sample_value');
    if(!empty($key)){
    echo 'Field Name: ' . $key . '';
    }
    

    Well, thanks loads anyway, your class is awesome!

    t.

  256. zoe somebody

    Just another thank you to Dimas. Your class has been a great inspiration for me as well as incredibly useful.

    @Luke: The problem you are having is that the NONE state of the wp_dropdown_pages, wp_dropdown_categories is -1. And WPAlchemy_MetaBox only seems to be checking for NULL when deciding when to save and when to delete no longer used options. Since -1 is not NULL it is being saved as a new option regardless. I have been writing an abstraction to use WPAlchemy_MetaBox with automated form creation and the have_fields_and_multi() drove me crazy because of the very problem you are experiencing until I figured out why it is happening. I have only given a glance at the problem and had hoped to be able to send Dimas a pull request with a fix but haven’t had any time to attempt it yet.

    Until that is resolved it doesn’t seem possible to use wp_dropdown_pages or wp_dropdown_categories without creating a new entry every time the post/page is updated.

    Hope that helps. :)

  257. tcherokee

    Hello,

    First off, like everyone here, I just have to say thank you. Your work here is amazing and has helped me immensely.

    To be honest, I just learnt about meta boxes and custom taxonomies two days ago, but I have managed due to your tutorials and a couple of others to get my project close to completion.

    I have created a metabox for adding ingredients to a site, however i want them to be stored as a non-heirarchal custom taxonomy I have also created.

    The code for the metabox is below

    <?php have_fields_and_multi('tags')): ?>
    <?php the_group_open(); ?>
    <?php the_field('quantity'); ?>
    Quantity
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    <?php the_field('name'); ?>
    Name
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Type
    <?php the_field('type'); ?>
    <select name="<?php the_name(); ?>">
    <option value="type_mine"<?php get_the_value() == 'type_mine') echo $selected; ?>>--Select Type--
    <a href="#" rel="nofollow">Remove Document</a>
    <?php the_group_close(); ?>
    <a href="#" rel="nofollow">Add Document</a><a href="#" rel="nofollow">Remove All</a>
    

    Is it possible to have the name field stored as taxonomy tags.

  258. Luke

    Dimas, looks like the link didn’t work before, which would be helpful… here it is again. Thanks for the look. http://snipplr.com/view/48388/wpalchemy–trying-to-get-pages/

  259. Kathy

    @Dimas – awesome job with the screencasts! Will be using that right away. Thanks!

  260. zoe somebody

    Earnestly I want to give heartfelt thank you for your work on MetaBox. Your work is helping so many people up the quality of their work significantly, me especially. And thanks for the tip and screencast on the sortables. I will be implementing that shortly. Humorously enough I was thinking today while working on a client project about what happens when the client wants to reorder the content. And like your psychic, lo, an answer appears. Keep up the amazing work.

    Regarding have_fields_and_multi() I am not sure if you mean you are going to get rid of the entire functionality or modify how the…oh, you mean WPAlchemy_MetaBox::_loop(). Huh. I’ll keep an eye out and post through github so I don’t clutter up your comments anymore 😉

  261. matthew

    Hi there,

    I was just wondering when the image/file uploader tutorial will be posted?

    Thanks,

    Matt.

  262. tcherokee

    Hi Dimas,

    I have added both the metabox code and the taxonomy code to Gist.Github

    What I want to accomplish is when the metabox is saved, the value(s) in ingredients gets saved in the Ingredients taxonomy as well.

    Thanks for your help :)

    T.

  263. kathy

    @matt – i posted my code for using the uploader at:
    http://farinspace.com/wpalchemy-metabox/#comment-9163

    it likely isn’t as elegant or as powerful as when rxr and Dimas are cooking up, but it does work in the interim.

  264. matthew

    @kathy

    Hi Kathy,

    Thanks for getting back to me. I tried to use your method but when you used the default media uploader to add an image to the main text box it just added the image to custom meta box instead. Is this just a bug I’m experiencing or is that the way the meta box is intended to work?

    Matt.

  265. matthew

    @kathy

    Hi Again, I was looking at the wrong comment, I was looking at one much further up the page… my bad.

    ps love the domain name!

  266. kathy

    @matt- yeah i remember that bug, but was pretty sure i squashed it. thanks for the compliment on my domain… one day i might even have my portfolio site go there. eventually

  267. shag

    howdy. I’m having some issues with get_index(). The index seems to work for any existing groups and if you add just one more group but not for any subsequent groups added before saving the page.

    In other words. If I have 5 entries that already exist when I come to my edit page, The indexes are all correct (0-4). If I add ONE group (or entry) using a docopy- button, The index on that group is correct (5). However any groups added after that first one have the same index (5), rather than incrementing (to 6, 7, 8 etc.).

    Is this a bug or is there an error in the way I’m doing things.

    If that is expected functionality, How can I create (and save) an incremented index for each new group (entry)? I will potentially have the need to add several entries before saving the page and other scripts on the page require a unique ID on certain elements.

    Thanks, Shag.

  268. kathy

    it is relatively easy enough to make a select list with all your wordpress pages, but i really like the layout/look of the wp_dropdown_pages list, so i worked a little string and preg_replace voodoo to make it work with WP alchemy. the form element in your metabox template:


    $mb->the_field('page_id');

    $dropdown = wp_dropdown_pages(array('show_option_none'=>'Custom', 'echo'=>FALSE));

    $dropdown = str_replace(array('name="page_id"','id="page_id"'),array('name="'.$mb->get_the_name().'"','class="page_id"'),$dropdown);

    $dropdown = preg_replace_callback('|value\=\"[0-9]+\"|','wp_alchify_dropdown',$dropdown );

    echo $dropdown;

    and the callback function.. supposedly you can use an unnamed function IN the preg_replace_callback so you don’t pollute the ‘namespace’ but i could never get that to work. note that i had to declare the object name of the metabox i was working with (so it isn’t perfect) as the callback only passes the $matches and you can’t send it the $mb variable.


    function wp_alchify_dropdown($matches){
    global $featured_metabox; //this is the object name of the metabox i am using the dropdown list in
    preg_match('|[0-9]+|', $matches[0], $int_matches);
    return $matches[0] . " " . $featured_metabox->get_the_select_state($int_matches[0]);
    }

  269. Leland

    @Dimas,

    Any dev version of the 1.4 branch ready for testing?

  270. Leland

    @Dimas

    This is looking amazing. The only big piece I badly need is the multiple media upload feature. Very cool drag and drop stuff. Do you have the 1.4 branch publicly accessible via github? Or are you holding off on publishing the new feature code until 2.0

  271. Alex

    Sorting now available with Media Upload coming? Sweet! 😀

  272. Leland

    @Dimas

    This is fantastic. I will download the lastest push and give it a try. Keep me updated as to when you would like that extra PR. You are the kind of developer we need speaking at Wordcamps….hint hint WC Vancouver…

    These developers tools are unlike any other tools available for theme development.

  273. Leland

    @Kathy

    Does your slideshow metabox code use the latest 1.4.4 version of WPalchemy with drag/drop and uploaders?

    http://img43.imageshack.us/img43/2867/metabox.png

    I would love to see that posted if it does.

  274. Gilles

    Hello,

    I use WPAlchemy_Metabox in a WP page “A”. When i want to display the data of this page on the front-end, no problem, my title, content and metabox data appear in my template.

    But if i want to display the data (title, content, metabox) of page “A” in my homepage with the function “get_template_part()” the title and content display but not the metabox data (and below the rest of the page is blank).

    If i use get_template_part() in my homepage but copy/past the code wich display just the metabox data from my page “A” to my homepage, it’s work.

    Is it possible to code the loop and the metabox code in the same WP page and call all these data with the “get_template_part()” in my homepage (WP 3.+) ?

    This is the code in my WP page “A”
    (it’s work if i call the page directly but not if i call the page by my homepage with get_template_part(‘pageA’); ) :

    $pagename='services';
    $args = array(
    'post_type' => 'page',
    'pagename' => $pagename
    );
    $the_query = new WP_Query( $args );

    while ($the_query->have_posts()) : $the_query->the_post();

    // page data
    the_title();
    the_content();

    // metabox data
    $custom_metabox_services->the_meta();
    while($custom_metabox_services->have_fields('docs'))
    {

    $custom_metabox_services->the_value('title');
    $custom_metabox_services->the_value('link');

    }

    ...
    php endwhile;

    And i want to call this page “A” in my homepage like this :


    ...
    get_template_part('pageA');
    ...

    Any idea ?

  275. Gilles

    Oh sorry !

    I see (to late) in the comment above that the problem has already been treated.

    It’s work well with : global $custom_metabox_services->the_meta();

  276. Kaiser

    Hi Dimas,

    “bug” report: If you didn’t specify the $arg “title”, then the meta box simply won’t appear. I saw that you added a notice on die(); for other stuff. Maybe you want to add a notice for this one too.

    Btw: Thanks for Wp Alchemy, it absolutely rocks!

  277. Leland

    @Dimas

    Great, looking forward to your upload screenr.

  278. kathy

    @Leland,

    Yes, I believe the code I posted uses 1.4.4. if it doesn’t have the drag/drop fields, i merely just added the code from Dimas’ screencast, so there is nothing extravagent there. I’d check and post again, but my internet access is really spotty of late.

  279. Leland

    @Kathy

    Okay awesome – I just want to make sure I’m using the latest version with wp uploader and drag/drop stuff. I’m hoping to build a nice custom post type with these custom meta box features. Thanks again.

  280. paul

    Almost 400 comments here.

    This is making it really hard to follow the development.
    ( It’s confusing to figure out which issue is already been fixed, or which request is on – or not on – the list. )

    Would it be better to keep this page only for documentation, and open another page or for discussions ?

    Anyway, Thank you for sharing this scripts ( by far, the best, the most promising – actually looks like it’s already, the promised land of custom meta box implementation ! )

  281. pixenjoy

    I could suggest bbPress (http://bbpress.org/). Easy to install with WP.

    Justin Tadlock use this forum on his website ans it seems to be great : http://themehybrid.com/support/

  282. Carlos Takemura

    Even better as a forum solution is Vanilla:

    http://vanillaforums.org/

  283. kaiser

    Afaik, The Pods plugin (podscms.org) has got an easy to setup & manage add on for this. Scott K. Clark wrote it about a year ago, so i guess it’s pretty mature now and would fit perfectly (in context) to your meta box class.

  284. Kaiser

    Forgot: Demo -> http://scottkclark.com/forums/ and download under http://podscms.org > Packages > bbForum

  285. Theo Ribeiro

    Hi all,

    I’ve been using WPAlchemy metaboxes to build a quite complex website, BRAVO Dimas for bringing it to us!!

    I’ve been strugling with one thing I can’t solve and that is allowing users to SEARCH the Custom Field Values.

    I’m using the class with the mode WPALCHEMY_MODE_EXTRACT so I get the values on normal custom fields but I can’t get a reliable solution for search.

    I’ve tried plugins for custom field searching but they don’t play nice with the latest versions of WP.

    Do any of you have a nice solution for searching through the custom fields?

    Thanks loads!

    t.

  286. Victor Teixeira

    I think you could take a look on this trac ticket – http://core.trac.wordpress.org/ticket/15066 and maybe propose the include of your amazing class to WordPress Core.

    Please take a look.

  287. Victor Teixeira

    Theo Ribeiro: eu costumo usar o Relevanssi, muito melhor que o search do wp e está atualizado. É definitivamente o melhor plugin de busca.

    Translated: Theo Ribeiro: I usually use Relevanssi, much better than wp and the search is updated. It’s definitely the best search plugin.

  288. Heather

    Hello Dimas,

    First, thanks for the amazing work you’ve done here, not just in the initial development but in the continued support. I can only imagine how much time it has taken.

    I’ve been able to use WP Alchemy pretty well while building out a new site. But I’ve run into some problems when entering shortcodes in my metaboxes, and was hoping you might be able to help. I got the shortcodes to work fine with a single metabox text field. But when I use have_fields_and_multi, it keeps showing the raw shortcode text on my webpage. I tried the advice you gave @Said. I’ve also tried suggestions I found elsewhere for using apply_filters(‘the_content’) to get shortcodes to work from metaboxes, but nothing seems to work with the have_fields_and_multi code. Any suggestions?

  289. Theo Ribeiro

    Obrigado @Victor Teixeira, ontem depois de muitas horas de busca e insistência eu cheguei justamente no Relevanssi e agora estou usando ele feliz e contente! Realmente a melhor opção!

    obrigado

    Translated: @Victor Teixeira, yesterday after many many hours of searching for a better solution I eventually stumbled upon Relevanssi itself. Now I’m happily using it and it is indeed a great search plugin.

  290. Heather

    Dimas,

    Thank you, thank you! It finally works! It’s just so beautiful! 😀

  291. Vadim

    Hey so I had a previous question about how do I actually display the custom meta in my templates or posts and I was wondering if you can simply show me the basic code for say.. a single post?

    I’ve created a “$custom_metabox” with various fields like firstname, lastname, email, phonenumber, location…etc.

    Then I created a custom template page and called it “single-resume.php”. I think I only have a loop in the temple and nothing else. Here is my code..

    <div class="post" id="post-">
    ID, "title", true); ?>	
    'Pages: ', 'next_or_number' => 'number')); ?>
    

    Do you mind showing me how do I set this up for my custom meta to show up with those fields I gave you? (firstname, lastname, email, phonenumber, location)

    This is my function.php code..

    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_basic_information', // underscore prefix hides fields from the custom fields area
    'title' => 'Basic Information',
    'types' => array('resume'), // added only for pages and to custom post type "events"
    'template' => TEMPLATEPATH . '/custom/user_profiles.php',
    ));
    

    This is my user_profiles.php..

    First Name
    the_field('firstname'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Last Name
    the_field('lastname'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Email
    the_field('email'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Phone Number
    the_field('phonenumber'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Location
    the_field('location'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    </div
    

    Thank you and I really appreciate your help. School projects are getting more hard and hard..eh.

    Thanks.
    Vadim.

  292. Vadim

    Ok the user_profile.php didn’t really show up as i have it in the code. The tags are missing..
    I just have it how it is in the documentations..

  293. Leland

    @Dimas

    Any word on a screencast for the updated wp upload meta box?

    Thanks.

  294. Tolumi Adamson

    ok…some progress.

    I have been able to pull the data from my custom metabox and save it in a taxonomy using the following function

    function ingredient_save_action($meta, $post_id)
    {
    global $wpt_ingredients_metabox;
    $meta = get_post_meta(get_the_ID(),$wpt_ingredients_metabox->get_the_value(wpv_recipe_ingredients),TRUE);
    foreach($meta as $metas) {
    wp_set_post_terms($post_id, $metas, 'wpth_ingredients');
    }
    }
    

    I have not been able to pull the specific value i need and it is the full array that gets pasted in my custom taxonomy

    a:1:{s:22:"wpt_recipe_ingredients";a:3:{i:0;a:3:{s:19:"wpv_recipe_quantity";s:2:"10";s:22:"wpv_recipe_ingredients";s:4:"test";s:20:"wpv_ingredient_units";s:9:"envelopes";}i:1;a:1:{s:20:"wpv_ingredient
    

    I was wondering can i pull the value from the “wpv_recipe_ingredients” which should be “test”

  295. Vadim

    Dimas, yeah I followed those instructions and inserted the code into my template file but no meta box data shows up when page loads. I was just wondering if I’m dropping in the code correctly or into the right place?

  296. kathy

    Hi Dimas,

    I was attempting something similar to the standard WP loop that tests if there are any items in the WPA group before going through the while loop. I thought it might be good to have an if/else situation and an error message if there was no content.

    so i tried

    if($featured_metabox->have_fields('slides')){

    while($featured_metabox->have_fields('slides')){
    if($featured_metabox->is_first()){ echo '1st bacon';}
    if($featured_metabox->is_last()){ echo 'last bacon'; }
    }
    } else { echo "you borked it"; }

    but when there is content, something about that first if statement seems to invalidate the is_first() function and it never triggers.

    is there a way to do this or might it be considered for a future release? cheers!

  297. kathy

    @dimas – awesome! that was it. i noticed (now that i know what the function is called) that you’ve answered this same question several times in the comments. first, thanks for answering me anyway! and second, maybe if you get a minute you could add it to your awesome docu so hopefully we can stop pestering you about it. :)

  298. Joe

    So, anyone have any idea on how we could incoporate WordPress 3.1’s new Internal Linking feature into a metabox?

    It’s currently only availabile via the TINYMCE editor… but i’m sure there’s a way to get it into a metabox….

  299. Joe

    Kathy I just wanted to say I find it hilarious that you use “Bacon” for your echo statements. I’ve echo/print/alert/trace’ed the term “Bacon” for years. :) Strange, it’s always the first thing that comes to mind.

  300. Joe

    From: http://wordpress.stackexchange.com/questions/8749/use-wp-3-1-internal-linking-widget-as-a-meta-box

    I see we have these files…

    /wp-includes/js/tinymce/wp-mce-link.php
    /wp-includes/js/tinymce/plugins/wplink/js/wplink.js

  301. kathy

    @Joe- lol, indeed. i think i stole the idea from Ian Stewart when I was first learning Thematic and never saw any reason to change it! usually i set up my ‘fail’ condition to say something like ‘no bacon for you’, so it is extra disappointing!

    i think dimas has a post on using multiple text editors, which is where i got the following code. but now that WPA supports footer_action you don’t need to use the normal add_action call. you can do it in the metabox declaration.

    add this to your metabox array:
    ‘foot_action’ => ‘my_admin_print_footer_scripts’,

    and then this is the function:
    http://pastebin.com/4wjK2sTz

    i just tested it and it gets all the new buttons that you might have added to your editor.

  302. Paul

    Hi Dimas,

    Thanks for all your hard work on this – it is an amazing framework for developers.

    I have got the metaboxes setup perfectly for custom post types and the data being successfully displayed in the front end templates. However, I am having difficulty with a metabox I have created for a singular page (Contact page). My issue is I can’t for the life of me get the data displaying in the front end template. Here is my code:

    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_custom_meta', // underscore prefix hides fields from the custom fields area
    'title' => 'Publisher and Agent Details',
    'template' => TEMPLATEPATH . '/custom/contact.php',
    'include_post_id' => '26',
    ));
    
    Enter Publisher details here:
    Publisher Title
    the_field('publisher_title'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Enter in a title
    Publisher Details
    the_field('publisher_description'); ?>
    <textarea name="the_name(); ?>" rows="3">the_value(); ?>
    Enter Agent details here:
    Agent Title
    the_field('agent_title'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Enter in a title
    Agent Details
    the_field('agent_description'); ?>
    <textarea name="the_name(); ?>" rows="3">the_value(); ?>
    

    The data is successfully saving to the particular Page ID.

    Would you be able to give me the template tags for retrieving this content on the front end?

    Also an indication of where they have to appear, ie. In the Loop etc.

    Many thanks
    Paul

  303. kathy

    @paul – did you read this section?

    http://farinspace.com/wpalchemy-metabox/#template

  304. Paul

    Thankyou Dimas & Kathy for the replies…. I think it was a case of midnight coding brain not working – as it worked perfectly this morning. Now onto setting up multiple WYSIWYG editors.

    Thanks again.

  305. kathy

    @dimas – do you have an example of a save filter?

  306. Gilles

    Is it possible to export/import the metabox content (xml file) with the WordPress import/export feature ?

    This doesn’t work for me (just ok for the post/page content)

  307. Caleb

    @NetConstructor.com: I’ve managed to fix that issue by replacing this part of your code:

    the_field('my_terms'); ?>
    <select name="the_name(); ?>">
    <option value="term_id; ?>"the_select_state($term->term_id); ?>' . $term->name; ?>
    

    …with this:

    the_field('my_terms'); ?>
    <select name="the_name(); ?>">
    <option value="name; ?>"the_select_state($term->name); ?>' . $term->name; ?>
    

    Note, change the value form using $term->term_id to using $term->name. $term->term_id seems only to be for hierarchical taxonomies.

    Hope that helps :)

    Caleb

  308. Aaron Vanderzwan

    @Dimas

    Thank you. I can only imagine how much time you have spent on this, answering questions, etc. Your dedication is admirable and this comment is simply to say thanks.

    (and to follow this thread via email.)

  309. Scott Wood

    @Dimas,
    I am going to second the previous statement. You have given us a great tool and spend a lot of time helping us save time.

    You… rule. Thank you!

  310. Vince Kurzawa

    Thanks for the incredible class you’ve put together. I’m still learning it’s ins and outs but its helped a lot so far.

    I am excited you’re working on a admin options/plugin class, this will be very helpful.

  311. Angelia Baladon

    Just another giant THANK YOU! I also saw your work being referenced as the “goto” example of a possibly upcoming WP metabox class … most excellent!

  312. Rhiannon

    Dimas, the MediaAccess class doesn’t work well within have_fields_and_multi.

    This has to do with the value of $wpalchemy_media_access->setGroupName and how the “last tocopy” group is constructed

    Specifically:
    – Add one field, then save. The last field gets duplicated.
    or
    – Add multiple fields at once, all of them get the same value, plus a duplicate shows up after saving.

  313. Rhiannon

    No, thank you for the great work :)

    Anyway, I managed to fix this particular problem by changing line 357 from this

    wpalchemy_mediafield_selector = '.field_class_name; ?>-' + name;
    

    to this

    wpalchemy_mediafield_selector = $(this).siblings('.field_class_name; ?>-' + name);
    

    I made other changes, I’m posting them in case they are useful to other people – and so you can work on them if you like them, since I’m kind of a noob at programming.

    First of all I added a quick and dirty way to open the media library to a specific file type. i.e.

    http://example.com/wp-admin/media-upload.php?post_id=136&tab=library&post_mime_type=video&TB_iframe=1&width=640&height=1024
    

    Here are the modifications to MediaAccess.php:
    Add this:

    private $tabtype = null;
    public function setTab($name)
    {
    $this->tab = $name;
    $this;
    }
    public function setTabType($name)
    {
    $this->tabtype = $name;
    $this;
    }
    

    Then modify public function getButtonLink like this

    public function getButtonLink($tab = null, $tabtype = null)
    {
    // this is set even for new posts/pages
    global $post_ID; //wp
    $tab = isset($tab) ? $tab : $this->tab ;
    $tab = isset($tab) ? $tab : 'library' ;
    $tabtype = isset($tabtype) ? $tabtype : $this->tabtype ;
    $tabtype = isset($tabtype) ? $tabtype : 'all' ;
    if ($tab = 'library')
    {
    return 'media-upload.php?post_id=' . $post_ID . '&tab=' . $tab . '&post_mime_type=' . $tabtype . '&TB_iframe=1';
    }
    else {
    return 'media-upload.php?post_id=' . $post_ID . '&tab=' . $tab . '&TB_iframe=1';
    }
    }
    

    Then, following your video tutorial on making the groups sortable, and by looking around in WP core code, I managed to style the sorting animation in a similar fashion to that of sorting the entire metaboxes.
    This goes in the metabox template.

    jQuery(function($)
    {
    $('#wpa_loop-video').sortable
    ({
    placeholder:"sortable-placeholder",
    cursor:"move",
    distance:2,tolerance:"pointer",forcePlaceholderSize:true,helper:"clone",opacity:0.65,
    update: function()
    {
    // Update the additional styles
    $('#wpa_loop-video div:even').css("background-color", "#eee");
    $('#wpa_loop-video div:odd').css("background-color", "#fff");
    }
    });
    // Set some additional style. In this case, alternating background color
    $('#wpa_loop-video div:even').css("background-color", "#eee");
    $('#wpa_loop-video div:odd').css("background-color", "#fff");
    });
    

    There’s one last thing I’d like to ask you. Is there some way I can allow only a specific file type in the uploader for each group? Say I want a group for uploading a video, another group for a picture etc., and I want to make absolutely sure the end user can only upload the correct file type for that field.

    Thanks again :)

  314. Rhiannon

    @Dimas
    Ops, I just saw your reply. Testing now, thanks :)

  315. Joe

    I am using the Data Storage type: “Extract” for 3 fields- Address, Latitude, Longitude and wish to run an SQL query to display only these 3 columns with their values.

    However I can only figure out how to get one of the columns to show, and it’s data by running this:

    SELECT DISTINCT wp_postmeta.meta_value AS address
    FROM wp_postmeta, wp_posts
    WHERE post_type = ‘dealers’
    AND wp_postmeta.meta_key = ‘_dealer_address’
    ORDER BY wp_postmeta.meta_value

    Could someone point me in a direction of how to run the query to include all 3 columns?

    Thanks.

  316. Joe

    @Dimas,

    Your solution did work in setting up the table in the format I was looking for (in your first example).

    What I’m trying to do is mimic the setup of the table in this: http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html#outputxml

    Because I have a custom post type (dealers) using your custom metabox for latitude and longitude.

    Your SQL query tested just fine in phpMyAdmin and looked identical to my other manually-created test dealer table, but when I tried to replace the google maps example query in the PHP- it was a no-go.

    Is it too complicated of a query you think?

    original test query in the PHP: $query = sprintf(“SELECT address, name, lat, lng, ( 3959 * acos( cos( radians(‘%s’) ) * cos( radians( lat ) ) * cos( radians( lng ) – radians(‘%s’) ) + sin( radians(‘%s’) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",

  317. Micha

    Great stuff.

    I ran into a possible bug though, and it’s a bit of a weird one. When using only one single checkbox, WordPress throws warnings:

    Notice: Undefined index: rtws_featured_items in /xxxxx/wp-content/themes/childtheme/WPAlchemy/MetaBox.php on line 2090

    Notice: Undefined index: rtws_featured_items in /xxxxx/wp-content/themes/childtheme/WPAlchemy/MetaBox.php on line 2090

    Warning: Cannot modify header information – headers already sent by (output started at /xxxxx/wp-content/themes/childtheme/WPAlchemy/MetaBox.php:2090) in /xxxxx/wp-includes/pluggable.php on line 897

    I found two different ways to avoid this:
    1. Turn off debugging (obviously)
    2. Add any other field – this is the part that seems weird to me

    Here’s my template:
    the_field('rtws_featured_item'); ?>
    <input type="checkbox" name="the_name(); ?>" value="on"the_checkbox_state('on'); ?>/> Feature this on the Homepage

    the_field('ab_solute_non_sense'); ?>
    <input type="hidden" name="the_name(); ?>" value="the_value(); ?>"/>

    It’s a hidden field that does nothing, at least nothing I need. I bumped into this “solution” when I noticed the warning while modifying your example template, deleting the fields I didn’t need bit by bit.

    This is not really a grave error, and I’ve been using a number of plugins that also stop WordPress in its tracks when WP_DEBUG is switched on, but I still thought I should ask about this. I should add that I’ve been playing around with custom meta boxes a lot recently – so it’s possible that I’ve polluted this WordPress installation before trying your script on it.

    Is this something you’ve seen before, and can you see or guess what’s going on? I’ll try to reproduce this on a clean WordPress installation soon, but I thought I’d check back here first.

    Thanks,
    M.

  318. Sahan

    Thanks a lot for this awesome class :)

  319. Bill

    Hi, what’s the best way to sanitize the data when using the fields in a template file?

  320. Brad

    Will this allow adding a meta box to a taxonomy? So it shows up on the add screen and not just the edit screen of the taxonomy, say like a extra field on the category type..

  321. Brad

    @Dimas, maybe I’m not approaching this correctly. I’m learning still and this seems like a simple task that even WordPress should support, so maybe I need to approach this differently?

    Here is what I’ve done:
    I have a new custom post type called advertisements. After that I wanted categories for the advertisements called Stores. So, when my client goes to add a new store, meta fields will be available for the store like Image, Url and such.

    So I created a taxonomy to the custom post type. But the meta fields are only visible when editing, this is backwards. So for a client to add a store, they would need to use the add function from the Store menu option, after adding the category then go and edit to add the additional fields, this is quite redundant.

    But it’s not just your plug-in, it seems like everywhere I go all WordPress shows is edit field entries, nothing for the add screen. I’ve spent many hours searching and it’s frustrating and silly.

  322. Brad

    @Dimas, what you did was really good work, the video and code clearly allow assigning meta to a specific category post, hiding when not needed, definitely great information but not what I was looking for, but I can see why you thought that.

    I was talking about when adding a taxonomy category assigned to a custom post type. Not when adding the custom post type. Maybe I will send you a video or code.

    Lets say I have Admin custom Post type menu option of Coupons.

    Coupons
    Add new coupon
    Categories
    Stores

    The stores menu option is nothing more than a taxonomy assigned to the Coupons custom post type. So when I click stores, it takes me to a category screen, it’s on this screen that I need to assign meta fields. I hope you understand now. Thanks

  323. Dimitar Chakarov

    Hi there,
    That’s a great class and I’m using it and loving it. I have a question:
    In my project I have products in categories and news. The news could be about a product category and when that is the case, I put them in that category as well. So I can have a post that is both in News category and Products->Clothes category, for example. I have a metabox with include_category => ‘products’, but it shows on my news posts, because they are too in that category. Adding exclude_category => ‘news’ didn’t work, because as you said “When you use exclude and include options together the include option will override any exclude options”. I have other categories as well (and the client could add some later), so I can’t just exclude news. Can you advice me what to do? I thought of editing the class, but figured I should ask first.
    Thanks.

  324. Dimitar Chakarov

    That sounds helpful, thanks. How can I get the post id inside the filter function? I suppose I could try with $_GET[‘post’], but is there another way?

  325. Dimitar Chakarov

    Thanks, it works great!

  326. konradk

    hello :)

    is there any possibility to hide editor only in some custom post type?

    i create custom post type called ‘imprezy’, then i add metabox like that:

    $imp_metabox = new WPAlchemy_MetaBox(array(
    // some other configs…
    ‘types’ => array(‘imprezy’),
    ‘hide_editor’ => TRUE
    ));

    this hides editor from ‘imprezy’ content type, it is ok. but it also hide editor in regular post, which i want to avoid. any solution for this?

  327. Bill

    Dimas, would it make sense to augment:

    $custom_metabox->the_value();

    So that the_content filter is applied to it?

    If I’m reading your code correctly, the_value() just echoes the field out. thanks.

  328. tcherokee

    Hi,

    I am wondering if you can help with this request. I am currently using gravity forms to create a front end form for my custom post type and I am wondering if it is possible to integrate your metaboxes within the front end form so users can fill out a form which will update the metaboxes.

    T.

  329. Bill

    When I use the hide_editor parameter and set it to true, it hides the editor for my POSTs, not just the custom post type I’ve declared. Here’s the code I am using:

    http://pastebin.com/ypTfLHDc

    If I set it to “false”, the editor box shows up on POSTs. If I set it to true, the box is removed from POSTs. Any idea why this would be affecting posts and not limited to my custom post type? thanks.

  330. Bill

    Thanks Dimas. When I copy your code (and change ‘event’ to my custom post type) , I still get the problem. The editor box fails to display on both my custom post type and ‘post’.

    Specifically, both editing screens have this CSS in the page:

    #postdiv, #postdivrich { display:none; }

    I will keep looking.

  331. Bill

    Dimas, just curious — when you defined your ‘event’ type, did you add support for the editor?

    'supports' => array('title','author','thumbnail','editor'),

  332. Bill

    Dimas, one more tidbit.

    In my testing, it’s only hidden on the “add new” post page.

    /wp-admin/post-new.php

    If I edit an existing post, it displays.

  333. Melinda

    I successfully used this class in a wordpress 3 site. For some reason on a wordpress 3.1.2 site I get the following error:
    Warning: parse_url() expects exactly 1 parameter, 2 given in /home/4/7/8/2292/2292/public_html/wp-content/themes/cousins/WPAlchemy/MetaBox.php on line 981

    Here is the code in my functions.php file:

    /////////////////////////////////Meta Box Creation//////////////////////////////////////
    include_once 'WPAlchemy/MetaBox.php';
    // include css to help style our custom meta boxes
    if (is_admin()) wp_enqueue_style('custom_meta_css',get_bloginfo('template_url') . '/custom/meta.css');
    // add Client Signature for Testimonials custom meta box 
    $custom_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_client_signature',
    'title' => 'Client Signature',
    'types' => array('testimonials'), // added only for pages
    'context' => 'normal', // same as above, defaults to "normal"
    'priority' => 'high', // same as above, defaults to "high"
    'template' => TEMPLATEPATH . '/custom/client_signature_meta.php'
    ));
    

    Any idea what is causing this and how to fix it?

  334. pb

    Do you have some example with Media Uploader

  335. pb

    Hi Dimas,

    Excellent stuff from you – thanks

    I am having a problem where I cannot get metabox to work with the custom post type (News – in my case), no data is saved.

    $custom_news_metabox = new WPAlchemy_MetaBox(array
    (
    ‘id’ => ‘_custom_news_metabox’,
    ‘title’ => ‘News – external source’,
    ‘types’ => array(‘news’),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,
    ‘template’ => TEMPLATEPATH . ‘/custom/external_meta.php’,
    ));

    but this work and I only want to have the field for News

    $custom_news_metabox = new WPAlchemy_MetaBox(array
    (
    ‘id’ => ‘_custom_news_metabox’,
    ‘title’ => ‘News external source’,
    ‘types’ => array(‘post’,’page’, ‘news’),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,
    ‘template’ => TEMPLATEPATH . ‘/custom/external_meta.php’,
    ));

    Any suggestions?

  336. pb

    I just tried v1.4.5 it works fine but using 1.4.6 causes the problem.

    Thanks for the help

  337. Bill

    Dimas, thanks — my problem is solved. :)

  338. Francesco

    Hello Dimas. First: Thank you for this awesome class! It solves a lot.

    I think that there’s a compatibility problem with More Fields (http://goo.gl/9zkN1) plugin.

    If I have a field created with More fields (for other post type) with the same name of the one created with Metabox, Metabox saves in DB only the meta_key value and not the meta_value.

    Did you noticed that?

    Regards, Fracesco.

  339. Antonello

    Hello Dimas, I have several custom field saved in the DB by plugins.

    I switched to Metabox because it rocks, but in the post editor it does not show the old values (I use the same meta_key of course).

  340. Antonello

    Thank you for your reply Dimas.

    I used More fields to save data in standard WP format (e.g. meta_key = “key1” and meta_value = “value1”). No array, just one key and one value for each field.

    I configured Metabox to use WPALCHEMY_MODE_EXTRACT so it saves data in an identical manner as More field does (as I see in the DB). The problem is that Metabox cannot read data saved before, even if they were saved with the same identical key.

    regards, antonello

  341. Bill

    Antonello, I was in a similar boat and got it to work.

    Check your database, in the post meta table there will be a _slug_fields entry. The slug will be the slug you assigned to the meta box.

    This option holds a serialized array of your various fieldnames and seems to be required. I created this for each post, and then my values showed up.

    Let me know if this doesn’t make sense.

  342. Antonello

    Thank you Bill! I will check it and report

    Antonello

  343. pb

    Hi Dimas,

    Thanks for providing the fix…works great.

    One question: if the meta data is stored as array how do you query using query_post (i.e. values inside array)

    query_posts('meta_key=somekey&meta_value=samevalue')

    Code tips please

    Thanks

  344. Frances

    Hi Dimas,

    Thanks for the great code, I’ve been using it a lot lately.

    I was wondering if there is an option to include/exclude based on parent page ID? I’ve had a look around and didn’t see anything though might have missed it.

    Thanks again,

    Frances

  345. Frances

    Hi Dimas, thanks for the quick reply. I added some classes to the body in admin-header.php that output the page ID and post_parent, and then in then just used CSS to display only on those child pages.

    Another question: Is it possible to use shortcodes in a metabox? I can output the shortcode string successfully as text, but unable to get it to resolve. I was originally basing this on:

    get_post_meta($post->ID, 'foo', true);

    Thanks again,

    Frances

  346. Bill

    Hi Dimas, do you have an examples which use save_filter and save_action? thanks.

  347. Bill

    Dimas, please ignore my previous note about save_action.

    But, I do have a question — is it possible to use WPAlchemy with a filed of type “file?” I would like to offer uploading of a file.

    When I add the code and dump the $meta with a save_filter script, the $meta variable does not include anything about the file being uploaded.

    thanks.

  348. Vince Kurzawa

    I am attempting to use WPAlchemy in a custom post type and all is going great so far except one thing. I can’t wrap my head around how to display my custom meta values in the admin post list. This is a custom post type in which I have custom columns outputting custom meta. From my functions file how would I call these values?

    Here’s a snippet of how it was setup before I started using the class:

    function xpsp_business_edit_columns($columns){
    $columns = array(
    "cb" => "",
    "title" => "Business",
    "email" => "E-Mail Address",
    "business_type" => "Business Type",
    );

    return $columns;
    }

    function xpsp_business_custom_columns($column){
    global $post;
    switch ($column)
    {
    case "email":
    $custom = get_post_custom();
    echo $custom["xpsp_business_email"];
    break;
    case "business_type":
    echo get_the_term_list($post->ID, 'business_type', '', ', ','');
    break;
    }
    }

    Your help is greatly appreciated. After this I can’t wait to play with the MediaAccess.php.

  349. Vince Kurzawa

    I answered my own question after some trial and error.
    I was trying to use the class to call the data as per the section of the guide above that describes using values in your template. This didn’t work from the functions.php file, so I used a standard get_post_meta call to retrieve what I needed.

    Here’s what I did:

    case "thumbnail":
    $src = get_post_meta($post->ID, '_xpsp_business', TRUE);
    $src = $src['logo'];
    if ($src == NULL) { echo "No logo uploaded."; } else { echo ""; }
    break;

  350. Luke

    Dimas: I just had a thought on having the ability to show a metabox based on a specific post format (gallery, video, aside, etc). I was thinking this would work similar to the include_template include option. Is there an easy way to do this currently?

  351. kathy

    @luke – i believe the include code for that is:

    ‘types’ => array(‘portfolio’)

  352. Luke

    @kathy – I gave that a shot but I didn’t work. I believe that is just for “Post Types”. I’m trying to show if a particular “Post Format” is chosen. This would require the post to be saved/published to know what post format has been selected. I initially had the same thought as you though…

  353. kathy

    @luke- you’re right, i misread your question. no idea if alchemy supports that yet. i haven’t seen it come up in the comments before and i’ve been subscribed to this thread for a long time. guess we’ll have to wait on the man himself!

  354. Luke

    @kathy – I haven’t either. I may fork it on github and give it a wack… Something like 'format' => 'video' might be an ideal solution

  355. kathy

    @Frances did you make any progress with the shortcodes? I am working on that myself right now.

  356. kathy

    @Frances – btw- yesterday Dimas updated his dev branch at github to work w/ shortcodes! it’s awesome.

  357. kathy

    hi dimas- another q for you… i’d like to use the same custom-meta.php template on 2 different templates… the meta info will be the same, but in the templates the data will go to different places. I am wondering if could do something like

    if( is template #1) { echo “this is for template #1; } else { echo “this is for template #2;}

    this would help me w/ duplicating posts and using the same template part (just called in a different place)

  358. kathy

    thanks dimas, i’ll have to check it out. i found that $post->page_template also works in the backend

  359. kathy

    do text inputs strip quotes by default? can i get around this with a save filter?

  360. Frances

    @kathy

    I got distracted with another task and now come back to shortcodes again with a different task. Shall look at the new dev branch.

    @Dimas,

    Thanks again!

  361. kathy

    something has happened where the tinyMCE text editors don’t save the html formatting anymore? I also noticed that text inputs aren’t saving quotes. epic bad timing.

  362. Kathy

    went back to 1.4.4… which is what I was using before and I am still stuck. Am using the code from Aaron’s comment on your multiple WYSIWYG editors post.

    http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/#comment-body-14642

    if i look at the editor via the HTML button, the p tags are there, but they aren’t getting saved.

  363. Eric H

    This is great, I’ve got it up and running on a site i’m currently building. I’ve ran into a minor problem. When I try to order post by title it seems to break everything. I’m using a Thematic child theme. Here’s my loop: $loop = new WP_Query( array( ‘post_type’ => ‘rentals’, ‘availability’ => ‘available’, ‘posts_per_page’ => 10, ‘orderby’ => ‘title’ ) );
    Works great if I get rid of ‘orderby’ => ‘title’.

  364. Rich Staats

    Do you have a donate button? I’d like to contribute, but find myself having less time than money. I’d be happy to throw some loot your way for all the hard work. This is exactly what I need.

    Rich

  365. Bill

    Dimas, is it possible to put a metabox with content = “side” but have it appear below the PUBLISH metabox? I can put it at the top, above the PUBLISH metabox (priority=high). But, if I set priority to “low”, the metabox loads below a taxonomy metabox that I also have. Just wondering if I can force the new metabox to load immediately below the PUBLISH metabox.

  366. Bill

    that should be “context=side”, not content. ie:

    Dimas, is it possible to put a metabox with context = “side” but have it appear below the PUBLISH metabox? I can put it at the top, above the PUBLISH metabox (priority=high). But, if I set priority to “low”, the metabox loads below a taxonomy metabox that I also have. Just wondering if I can force the new metabox to load immediately below the PUBLISH metabox.

  367. Federico

    I’m using the wordpress plugin “Relevanssi” to improve the search on my site. it acutally works pretty good except it doesn’t look in the metabox I declared with alchemy… how do they are saved as in the wp structure?
    the plugin enable me to search in custom post type, taxonomies and custom fields.

  368. kathy

    hi dimas, is there any way to filter the wp_kses on a per metabox basis? i’d like to use one for embed code (and iframe actually) and it gets stripped on save.

  369. Luke

    @kathy Have you tried using a textarea? I use that for embed codes and so far haven’t had any trouble. I believe the regular text input won’t work.

  370. kathy

    @luke – yes i’m using a textarea. tried to put in an iframe and no joy.

    @dimas- thanks. i thought it was going through the kses somewhere along the way… as i thought that was the reason the iframe was getting stripped. i’ll check out save filter and report back.

  371. Brett Johnson

    I’m dreaming of a setup where a metabox is created for every term is a custom taxonomy. The inputs would be same in each box but would have a name that associate with the given taxonomy term. How feasible is this or is it even possible?

  372. Bobby

    **novice alert**

    I’m trying to incorporate this into an existing plugin that I have forked and it currently has some data that it passes via an array. Is it possible to pass in that data to, say, a select box?

  373. Sean

    A quick question regarding have_fields_and_multi for repeating fields: is it possible to have a repeating field group within another? My situation is this:

    A friend has a site for portfolios she creates. There’s a materials section, where I would first like a repeating field to create different material groups (i.e. Acrylics, Metals, etc.). Within each dynamic material group (i.e. Acylics) there would be the ability to create multiple options (i.e. Acrylic Red, Acrylic Blue, etc.)

    Ultimately all this information gets plugged in as form options dynamically, hence the complexity of this.

    This might be completely straight-forward but I thought I would check to make sure it’s not an issue. Thanks!

  374. Sean

    Thanks for providing the code!

    I’m still wrapping my head around it to be honest. Is there anything else to be added for the HTML? I.e. any of the typical code you’ve setup for WPAlchemy?

  375. Lawrence

    Please pardon my question as I am new to WP and PHP, but while I have found your Class helpful, I for the life of me cannot get it to pull anything from it. I have been able to set it up on the back end of WP (Create MetaBoxes on a specific page), but when I go to call anything on the front end I just get:

    Fatal error: Call to a member function the_value() on a non-object…

    I don’t understand what I am missing. I am calling the global at the start of the page template and calling the information through:

    the_value(‘board_name’)?>

    I am completely lost…

  376. Lawrence

    I have tried several different object calls, including:

    get_the_name()

    And have not been able to call anything. I consistently am getting Fatal errors over anything WPAlchemy related.

    Need help ASAP.

  377. Lawrence

    I am at a complete loss. I have been fighting this all day, and I am either too green or looking in the wrong parts to get this to work.

    I set up a Meta box with the following code in functions.php:

    new WPAlchemy_MetaBox(array
    (
    ‘id’ => ‘_about_mission’,
    ‘title’ => ‘Our Mission’,
    ‘template’ => TEMPLATEPATH . ‘/custom/about-mission.php’,
    ‘include_template’ => array(‘about.php’) // use an array for multiple items
    // ‘include_template’ => ‘product.php,press.php’ // comma separated lists work too
    ));

    Then, in the Meta box template file I put as follows:

    Enter Statement

    the_field(‘our_mission’); ?>
    <textarea name="the_name(); ?>” rows=”3″>the_value(); ?>

    I then proceed to try and call it:

    have_fields(‘our_mission’))
    {
    echo ”;
    $ingredients_metabox->the_value(‘our_mission’);
    echo ”;
    }
    ?>

    Now, I just used a snipet of code after fighting with my own code for so long and I still couldn’t get it to pull anything through.

    Help me, someone! Gah!

  378. Lawrence

    I just copy/pasted every single line verbatim from the documentation and still cannot pass any of the things define from MetaBox.php. NOTHING. I still continue to get a Fatal error. I absolutely do not understand.

  379. Lawrence

    Now I just copy pasted the whole contents from MetaBox.php in to my functions.php file and still nothing will pass from this. What is going on?!

  380. Travis

    Dimas – amazing stuff! Thanks so much.

    I have run into a strange problem with post meta not being “attached” to posts after migrating from one server to another. All data is there in post_meta table and actually can be got via get_post_custom(), though not using:

    get_post_meta(get_the_ID(), $meta_box_mb->get_the_id(), TRUE);

    The values also don’t show up in the admin (as in on the pages they are attached to).

    I tried a quick copy on my local server and the issue persists. Anything you have seen before?

  381. Travis

    Forgot to mention:
    version 1.4.8
    wp 3.1.3
    sql export/import

  382. kathy

    Lawrence, you aren’t supposed to copy MetaBox.php into your functions.php. that is nowhere in the instructions. i suggest you stop, take a break, and come back w/ fresh eyes. seriously i often solve things in the morning in 20 minutes that where taking me 5 hours when i was frustrated. the class does work so it is just a matter of you following the docu to properly implement it.

    then- i can’t really tell if your code is posting properly. try using pastebin.com or putting your code between <pre><code></pre> tags.

    this part of the instructions covers the setup of the metabox
    http://www.farinspace.com/wpalchemy-metabox/#setup

    in your above posted code you are defining the metabox, but not setting it equal to anything. you’ve got to give it a name! (which could just be your code not posting properly… idk) so that later you can call it back.


    $ingredients_metabox = new WPAlchemy_MetaBox(array
    (
    ‘id’ => ‘_about_mission’,
    ‘title’ => ‘Our Mission’,
    ‘template’ => TEMPLATEPATH . ‘/custom/about-mission.php’,
    ‘include_template’ => array(‘about.php’) // use an array for multiple items
    // ‘include_template’ => ‘product.php,press.php’ // comma separated lists work too
    ));

    then you call it in your template following these instructions:

    http://www.farinspace.com/wpalchemy-metabox/#template

    assuming you setup your metabox object to be called $custom_metabox, you’d add the following.

    global $custom_metabox;
    $custom_metabox->the_meta();
    $custom_metabox->the_value(‘your meta field name’);

    to your template. and that will echo out the value you’ve saved for ‘your meta field name’

    dimas has included some sample code in the WP_Alchemy download. take a look at how he has set up his metaboxes.

  383. Travis

    Aha – that was it…

    Situation arose as I was storing full urls in the post_meta, then finding/replacing xyz.dev with longername.com on migration. Just did a quick check with moving the install to zxy.dev and everything worked perfectly.

    Guess I will just have to go back and redo some things so I am just storing ‘filename.jpg’ and deal with the rest of the URLs in the templates (which makes more sense too I suppose – laziness… ha).

    Keep up the good work!

  384. Lawrenc

    I apologize for seeming so frantic. I was butting heads with that all day, and as I said before, I am super green to PHP and WordPress.

    That being said, thank you so much! Kathy, thank you so much for clarifying and breaking some things down for me, and Dimas, thank you for being open for help yourself.

    In the end it was this line that was messing me up:

    $ingredients_metabox = new WPAlchemy_MetaBox(array

    I wasn’t defining the metabox, like Kathy so graciously let me know. Thank you both so much for being very willing with your knowledge.

  385. Lawrence

    Alright, ran in to another snag that maybe I could get some feedback on. I have been able to pull from all of the meta boxes using this awesome WPAlchemy Class, but I have been having issues with a instance. I am trying to take the values from the given code to then fill an unordered list. Essentially filling up the with ‘s as there is data to be called upon.

    I again apologize if my questions are terrible as I am new to PHP.

    I set up a meta box with the following:

    $members_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_about_members',
    'title' => 'Board Members',
    'template' => TEMPLATEPATH . '/custom/about-members.php',
    'mode' => WPALCHEMY_MODE_EXTRACT,
    'include_template' => array('about.php') // use an array for multiple items
    // 'include_template' => 'product.php,press.php' // comma separated lists work too
    ));

    The following meta box:

    have_fields_and_multi('board_members')): ?>
    the_group_open(); ?>
    the_field('board_name'); ?>
    Board Member Name
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    the_field('board_position'); ?>
    Board Member Position
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"/>
    Remove Board Member
    the_group_close(); ?>
    

    Then, I reference the functions at the top of my HTML:

    global $members_metabox;
    global $mission_metabox;
    $members_metabox->the_meta();
    $mission_metabox->the_meta();

    Following all of this, I attempt to fill my list:

    have_fields('board_members')) {
    if ($members_metabox->the_value('board_name')) {
    echo "" . $members_metabox->the_value('board_name') . " " . ",";						
    }
    if ($members_metabox->the_value('board_position')) {
    echo $members_metabox->the_value('board_position') . "/li>";
    }
    }
    ?>
    

    Thanks in advance for any help/advice/tips.

  386. Lawrence

    My bad, I didn’t know it would filter out the unordered list (ul) elements out of the last code snippet. I am trying to fill up an unordered list with list items (li) while pulling in the values.

    The code at the bottom should be wrapped in an unordered list (ul)(/ul).

    I am not super sold on this method, I am open to other ways of achieving the result. I am sure that my way is far from ideal.

    Thanks again.

  387. kathy

    lawrence, you aren’t setting up a loop. look again at the sample in: http://www.farinspace.com/wpalchemy-metabox/#template

    it isn’t enough to say have_fields()… have_fields() means nothing by itself, you must use it in setting up a while loop. i also like to first test to see if it has any values in it at all using have_value() …. which isn’t in the docu, but Dimas has answered for me previously in the comments.


    if ($members_metabox->have_value('board_members')):
    echo '';
    while($members_metabox->have_fields('board_members')) :
    echo '' . $members_metabox->get_the_value('board_name') . '';
    endwhile;
    echo '';
    endif;

  388. Lawrence

    Kathy, thanks for the speedy response! I went with your example, and I couldn’t get it to work. I then swapped out the second ‘board_members’ with ‘board_name’ and also changed the Mode back to default in my functions.php file and tried passing anything with several different code combinations with no result.

    You had characters missing from several quote marks, so I will paste how I set up your example loop:

    if ($members_metabox->have_value('board_members')):
    echo 'ul';
    while($members_metabox->have_fields('board_members')) :
    echo 'li' . $members_metabox->get_the_value('board_name') . '/li';
    endwhile;
    echo '/ul';
    endif;
    

    From this I am not getting anything to show in the DOM. Note: I took out the greater-than and less-than signs on the unordered and list elements to better show you what I am doing.

    I also attempted this way just to make sure I wasn’t misreading the code you presented. It too gave the same result.

    ul
    if ($members_metabox->have_value('board_members')):
    echo 'li';
    while($members_metabox->have_fields('board_members')) :
    echo '' . $members_metabox->get_the_value('board_name') . '';
    endwhile;
    echo '/li';
    endif;
    /ul
    
  389. kathy

    @lawrence – hmmm… that should have worked, b/c it is a stripped down version of working code that i am using. though apparently some markup is getting stripped even inside the code tags, weird.

    “also changed the Mode back to default in my functions.php file” i haven’t come across a need to use extract mode yet. for what it appears you are doing, i’d leave that section alone.

    i actually tested my code this AM (the hacked down version) and i get an unordered list of names. for this paste i just changed the names of the metabox and the fields/groups. check this paste and see if that helps.

    http://pastebin.com/hnMAWz7H

    you can also try a

    print_r($members_metabox);

    right after

    $members_metabox->the_meta();

    as that might tell you what is IN your metabox object. the values are saving correctly in the backend right?

  390. Bill

    Kathy rocks! :)

  391. Lawrence

    Kathy does rock! :)

    I tried this solution before and couldn’t get anything to work. Nothing is still showing up. However, I never tried using the

    print_r($members_metabox);

    code. I did this, and this is what was spit out:

    WPAlchemy_MetaBox Object ( [id] => _about_members [title] => Board Members [template] => /home/bhw1test/staging.bhw1.com/pm/wp-content/themes/toolbox/custom/about-members.php [types] => Array ( [0] => post [1] => page ) [context] => normal [priority] => high [autosave] => 1 [mode] => array [prefix] => [exclude_template] => [exclude_category_id] => [exclude_category] => [exclude_tag_id] => [exclude_tag] => [exclude_post_id] => [include_template] => Array ( [0] => about.php ) [include_category_id] => [include_category] => [include_tag_id] => [include_tag] => [include_post_id] => [init_action] => [output_filter] => [save_filter] => [save_action] => [head_filter] => [head_action] => [foot_filter] => [foot_action] => [hide_editor] => [hide_title] => [lock] => [lock_on_top] => [lock_on_bottom] => [view] => [hide_screen_option] => [meta] => Array ( [docs] => Array ( [0] => Array ( [board_name] => Kay Stoltz [board_position] => President ) [1] => Array ( [board_name] => Eric Johnson [board_position] => Vice President ) [2] => Array ( [board_name] => Cinde Johnson [board_position] => Secretary ) [3] => Array ( [board_name] => Steve Salvatori [board_position] => Treasurer ) [4] => Array ( [board_name] => Christopher Kelly [board_position] => Director ) [5] => Array ( [board_name] => Wayne McMorris [board_position] => Director ) [6] => Array ( [board_name] => Pat Munts [board_position] => Director ) [7] => Array ( [board_name] => Allyson Shoshana [board_position] => Director ) [8] => Array ( [board_name] => Steve Trabun [board_position] => Director ) ) ) [name] => [subname] => [hint] => [length] => 0 [current] => -1 [in_loop] => [in_template] => [group_tag] => [current_post_id] => 10 [_loop_data] => stdClass Object ( ) ) 
    

    It seems that the function is in fact able to pull from the meta boxes I created. I am just having a hard time understanding why it’s having difficulty fully pulling through.

    Is the fact that there are two values are am trying to pull from one multiple field messing me up? It seems like I would need a way to cycle through the possible values?

  392. kathy

    thanks guys. 😉

    looking at your print_r… where we’re expecting to see the group name (associated with have_fields_and_multi) to be ‘board_members’, i’m seeing ‘docs’ which makes me think you copied in Dimas’ have_fields_and_multi example and forgot to change the loop name in your metabox template.


    [meta] => Array ( [docs] =>
    Array ( [0] => Array ( [board_name] => Kay Stoltz [board_position] => President )
    [1] => Array ( [board_name] => Eric Johnson [board_position] => Vice President )
    ....truncated....
    )

    if you change it you’ll need to re-enter the date you’ve already added. or as a test you could change the output of my pastebin to have_value(‘docs’) and have_fields(‘docs’) …

  393. Lawrence

    Thanks, Kathy!

    I noticed that as well, and I checked and I believe I clearly made the correct change to the loop name:

    while($mb->have_fields_and_multi('board_members')):
    

    Could there possibly be something overriding this?

  394. Lawrence

    I changed the loop name on my template file to ‘docs’, without changing the following in my functions.php file:

    while($mb->have_fields_and_multi('board_members')):
    

    And as you noted, it is pulling it fine. I just don’t understand why it’s still pulling for ‘docs’ and not ‘board_members’. Is there another place I needed to change the ‘docs’ reference in the functions.php or other code that Dimas offered us?

  395. Lawrence

    Excuse me, I didn’t mean functions.php file, I meant from my ‘template’ file that houses the meta box. Sorry for the confusion.

  396. kathy

    the loop name must be the same in both your metabox template (in this case custom/about-members.php) AND in your output template… whereever you are calling the data .

    as i said in my last post, right now it appears to me that in your metabox template you are calling the loop ‘docs’ while in your output you are calling it ‘board_members’… which isn’t printing anything b/c nothing is stored in the meta for that.

    change the value in your metabox template. then resave your post.

  397. Lawrence

    Kathy, thanks again! You are so helpful.

    So I went in and did find that I hadn’t updated the about-members.php file and did so. I then updated the post, and I still am finding that it’s calling it ‘docs’. Do I need to deleted the page and re-create it for it to update itself?

  398. Lawrence

    Kathy,

    I didn’t bother to check the meta box. It was cleared and now I am able to enter in fields and have it populate.

    Thank you so much for your help! I will attempt to not bug you as much in the future. :)

    On another note, I was wondering if you could possibly point me in a direction to learn more on PHP? Most of what I have learned I was self taught through W3Schools.

    Thanks again!

  399. Lawrence

    Man, I thought I was out of the woods, but now I find that on the page with the meta box (about.php) I do not have any ability to add names/positions anymore. On top of that, I can’t ‘remove all’ from the meta box, nor can I use any other edit functions on that page.

    Any suggestions to what is bringing this about now?

  400. Vince Kurzawa

    We really need a WP Alchemy forum, these comments are getting difficult to follow. Any update Dimas? I recommend bbPress.

  401. kathy

    @lawrence – can’t really point you to a good place for learning PHP: though i end up at http://php.net and http://codex.wordpress.org all the time. i’m totally self-taught too- lots of time spent meticulously iterating and googling when things break. 97% of the time someone has already gone through the same problem, so get good with asking google. oh and lots of generous help from people who are more knowledgeable- which is important when you are still at a stage where you can’t form good search queries. don’t forget to pay it forward! it’s good karma.

    @Vince – agreed.

  402. Cliff

    Hi, this looks to be VERY useful for a project I am working on. I am interested in using this only for specific page templates, and after reading through, this sounds like it will work. On a only slightly related note, can someone suggest where I would start if I wanted to add a page template through a plugin?

  403. Ancas Horia

    Vote Dimas for mayor of WordPress !!! :)
    Seriously, WPAlchemy is really making up for some lacking features of wordpress and the new media upload integration is tasty.
    Good job sir.

  404. Sinklar

    Hi everybody.

    I’m building a quite complex custom post type structure and I would need some help regarding my metaboxes.

    What I want to do:

    1. Thank’s to the have_fields_and_multi() function, the user enters data in simple text input fields (with a “Add new” button)
    2. The values from the previous text inputs should be used to build a select dropdown in another metabox.
    To make it simple, here is a mockup (also attached to this post): http://idzr.org/0c95

    I have the first part working, it’s easy. But I can’t figure out how to make the second part to work. If I use a while($mb->have_fields_and_multi('aaa')) in another while($mb->have_fields_and_multi('bbb')) the page is infinite (the loop doesn’t end). If I use foreach I have other problems.

    Do you have an idea about how I can achieve this ? Thanks!

  405. Sinklar

    Thanks! I finally got it working with foreach before I saw your answer. The user has to save it before the items do appear in the select but it doesn’t matter…

    Now the million dollars question : in my theme template, is it possible to retrieve the entries sorted by the value of the select ?

    My metaboxes : http://cl.ly/2o2u0I2u2j3p1p3V2O1J

  406. kathy

    Hi Dimas, is there a way to limit the metabox by taxonomy in the same way as by tag or category?

  407. kathy

    thanks dimas! filling in the $taxonomy and $terms arguments this works just fine for now:


    function my_output_filter($post_id) {
    if(is_object_in_term( $post_id, $taxonomy, $terms)) {
    return TRUE;
    } else {
    return FALSE;
    }
    }

  408. Sinklar

    No help for me ? 😉

  409. kathy

    hi again dimas, did you know that if you put quotes in a text input they get stripped out (along w/ the text they were surrounding)? is this intentional? is it something that i should just work around with the save filter?

  410. Jonathan Wold

    Does include_category_id also work with custom taxonomies?

  411. Luke

    Dimas, I’ve been playing around with the shortcodes and it seems to working with one exception. When using a shortcode with two parts, a beginning and an end, nothing is returned.

    For example, when using WordPress’s video embed shortcode: [embed width="550" height="400"]http://vimeo.com/24840381[/embed], nothing is returned in the web page, but the option value still shows in the admin metabox field.

    When using a “self contained” shortcode, for example, [shortcode width="550"], things work as expected. I hope that makes some sense…

    Is there a way to process or output a “two part” shortcode? I’ve tried both a text input and a textarea to no avail.

  412. Nicole

    Quick question that I’m hoping has a simple answer.

    When you’re displaying the meta data in your templates, is there a way to code it so that html included within the get_the_post-meta tag is only shown if that meta field as been filled out? Sorry if I’m not wording this right, everything I know about php I learned from wordpress so my knowledge is kind of haphazard. For example, I have this code to display the ‘Client’ field:


    php $meta = get_post_meta(get_the_ID(), $custom_metabox->get_the_id(), TRUE);
    echo "Client:";
    echo $meta['client'];

    Right now, the Client: heading is still displayed even if that field wasn’t filled out in the post which, obviously, is not good. Is there something I can do so that if there’s no data in the ‘client’ filed, nothing in that bit of php will be displayed? I’m guess I’d need some sort of if/else setup but I’m not sure exactly how to do it.

  413. Jonathan Wold

    @Dimas – I include_category_id an initial try with no success. What I am going for is that a metabox shows up when a particular term in a custom taxonomy is selected. I realize that, unless I use a JS solution, it wouldn’t do it immediately. My test is a post type that already has the term selected and I am expecting the metabox to show up when editing that term. Am I on the right track?

  414. Luke

    Thanks, Dimas! Shortcodes are a bit strange in how some of them seem function. I’m basically trying to get a video shortcode to work (one that supports JW Player). I tried JW Player for WordPress Plugin shortcode but to no avail and now trying Pro Player shortcode without any luck. The JW Player in “self contained” and the Pro Player is “two part”.

    Any ideas on what I’m missing? A global call? Not a big deal, but would be nice to figure out.

  415. Jonathan Wold

    @Dimas, thank you for the suggestion to use the output filter! I’ll give it a try.

  416. Ethan

    Hi Dimas. Excellent work. This is fantastic. I have a question. Regarding the have_fields_and_multi function. Is it possible to re-order the field sets easily in the write window? Magic Fields has the ability to drag and drop field sets to a new order with repeating, or duplicated field sets. For example, if the user were entering ‘players’ as in the roster of a team. Each player is entered in a duplicated field set as meta data attached to the custom post type, ‘team’. Then, let’s say they wanted to change the order in which they entered the players, is there an easy way to do this? Maybe have a link for ‘+’ and one for ‘-‘ to move a field set up or down in the order?

  417. kathy

    @ethan – you can drag and drop w/ alchemy following dimas’ directions here:
    http://www.farinspace.com/sorting-wordpress-meta-box-fields/

  418. Ethan

    @kathy – many thanks for pointing me to the tutorial

  419. Mike

    Hi Dimas,

    Thanks for sharing with use, it helped a lot….

    @Kathy Thanks for comment support 😉

    @Vince I agree!

    Dimas when can we expect a bbPress to support the development?

  420. Mike

    @Dimas, that is great news, if you need any help let use know :-p

  421. Christian

    Hello – can you please help me to understand what I’m doing incorrectly?

    I am using this feature to show a list of events:
    http://riggswerks.com/clients/auriamicro (lower right corner).

    But all the events are sharing meta data. This is the way I’ve structured my php/html:

    https://gist.github.com/1038742

  422. Danny

    Hi Dimas,

    I’ve been using WPAlchemy for quite some projects now, it’s of great help so first of all: thanks a lot, you rock!

    What i’ve been wondering (it’s nitpicking though) is why you’re defining the _TEMPLATEURL constant instead of using get_bloginfo(‘template_url’). Not that it really matters, just thought you must have had a reason for it and I didn’t quite figure it out myself yet.

    Keep up the good work!

    Danny

  423. Danny

    Ah well, please disregard my previous comment. * slap myself *. It’s because of including the metabox templates and http wrappers. I feel kinda stupid now.. 😉

  424. Matt Hill

    I just wanted to say a massive thank you for this class. WPAlchemy is really awesome!

    I’ve tried pretty much every custom meta box plugin out there and while they are all very good at the basics, they all suffer from one problem or another.

    With WPAlchemy, although it’s more work to setup, I get complete control over every aspect of the meta box fields. It’s just so much more flexible. And the repeating fields and sortable option is nothing short of fantastic.

    Thank you, thank you for your great work, I really appreciate all the effort you’ve put into this. :-)

  425. Luke

    For what it’s worth, according to WordPress.org, it’s better to use:
    get_template_directory_uri() instead of using
    get_bloginfo('template_directory') and
    get_stylesheet_directory_uri() instead of using
    get_bloginfo('stylesheet_directory').
    Carry on :)

  426. Matt Hill

    One thing that I haven’t worked out how to do yet is show a thumbnail of the image that was selected from the Media Uploader. It would be great to show the thumbnail next to the meta box field that shows the path.

    I wonder if there is some example code for that?

  427. Luke

    @Matt – You could try something like this:

    if( $mb->get_the_value( 'example_image' ) ) : 
    echo 'get_the_value() ) . '" title="Link preview image" target="_blank">get_the_value() ) . '" alt="Preview image" />';
    endif; // end custom preview image check
    
  428. Luke

    This might come across better…?

    if( $mb->get_the_value( 'hero_background_image' ) ) :
    echo 'get_the_value() ) . '" />'
    endif;

  429. Matt Hill

    @Luke: Thanks for the tip. Your code seem to get mangled, but I got the sense of it. I see this will only work when you update the post, so eventually I’ll look for dynamic jQuery solution, but this works for now:
    http://twitpic.com/5f9qmq
    Many thanks :-)

  430. Matt Hill

    How would I create a WYSIWYG TinyMCE text area in my meta-box template?

  431. Matt Hill

    Cool, that’s looks perfect! Many thanks for the pointer. Do you have a PayPal donation button somewhere, I’d like to make a donation :-)

  432. Bill

    Possibly a dumb question… is it possible to use WPAlchemy when creating a theme options page?

  433. Matt Strange

    Hey,

    How would i echo the value of a custom field using a function outside the loop? I have tried this code in my functions.php file but doesn’t seem to do anything:

    function myfunction()
    {
    global $thePostID;
    $thePostID = $post->ID;
    $my_meta = get_post_meta($thePostID, $photo_metabox->$thePostID, TRUE);
    echo $my_meta['photo'];
    }
    

    Any suggestions?
    Thanks

  434. Ryan

    Maybe I’m an idiot but I can’t figure out how to display the data that was entered into the metabox fields in my theme….I know there’s the “Using The Meta Box Values In Your Template” section, but I’m not quite sure where to place that/how to integrate it.

    Anyhow, thanks!

  435. Moti

    It seems like non-ascii characters are not saved correctly while using WPAlchemy (I also verified it in mysql). Any suggestion on how to make it work?

  436. Matt Strange

    @Dimas

    Legend! Thanks man :)

  437. Jan

    Great class! Thanks a lot can I donate some money to say thank you?! Awesome … :)

  438. Javier Sanchez Toledano

    Hi Dimas.

    WPAlchemy is great! I’m only at the surface but what I see is awesome. Thank you.

    I also ask if you can point me in the right direction. I use a custom meta box to write some details about movies, you can see an example here http://j.mp/jrZ5Oi it’s called “Ficha Tecnica”.

    The goal is make a search with the names, but there are no results. If a name is in the post content, then I got the post, but how can I look into custom meta fields?

    Thanks again.

  439. Ma'moun

    Note that the constant TEMPLATEPATH you’re using in functions.php file doesn’t work with child themes. However, STYLESHEETPATH works.

  440. Javier

    Thanks Dimas!

    WPALCHEMY_MODE_EXTRACT was the key!

  441. Ma'moun

    What is the best way I can enqueue script/style in the pages that a specific meta-box is being loaded in? I am trying to do something like this:

    $custom_school_mb = new WPAlchemy_MetaBox(array(
    ...
    'head_action' => 'meta_tabs',
    ...
    ));

    function meta_tabs() {
    wp_enqueue_style( 'fkp-metabox-tabs', _TEMPLATEURL . '/css/metabox-tabs.css' );
    wp_enqueue_script( 'fkp-metabox-tabs', _TEMPLATEURL . '/js/metabox-tabs.js', array( 'jquery' ) );
    }

    but it doesn’t work…

  442. kathy

    @ma’moun – it’s init_action not head_action for enqueing stuff

  443. Ma'moun

    @kathy
    Oh, thanks. That did it!

  444. kathy

    dimas,

    i’m still not sure i’m enacting the save_filters right. basically i want it to ensure that if the user has selected ‘featured’ in the ‘featured_tax’ radio group, that the ‘excluded_tax’ radio group will be set to null. i can do it w/ jquery, but i guess i am always up for overkill… and just b/c i’d finally like to know how to use this correctly.


    function taxonomy_save_filter($meta, $post_id){

    if($meta['featured_tax']=='featured'){
    $meta['excluded_tax']=='';
    }
    return $meta;
    }

  445. Duane

    Hi :)

    I’ve setup a checkbox that I would like to use with a conditional. I’ve read through the documentation above and haven’t found what I’m looking for.

    Could anyone tell me how I would check if the checkbox is checked with an if statement? Is this possible?

  446. Max

    Hi, I’ve been trying to learn how to create my own meta boxes for a week now, and it seems like all the tuts i’ve tried don’t work with my thesis theme. I’m wondering if i’m using thesis should I put the functions.php code in my custom_functions.php file or not? I’m not to experience with php but I really want to get this down.