Custom Metadata

An easy way to add custom fields to your object types (post, pages, custom post types, users) & to generate option pages.

The goal of this plugin is to help you rapidly build familiar, intuitive interfaces for your users in a very WordPress-native way.

The custom field panel is nice, but not quite the easiest thing for users to work with. Adding your own metaboxes and fields involves a lot of time and repetitive code that could be better used elsewhere.

This plugin handles all that heavy-lifting for you behind-the-scenes, so that you can focus on more on building out and connecting your data rather than all the minor details. This single piece of code x_add_metadata_field( 'my-field-name', 'post' ); generates a metabox with a text field inside it, with the necessary hooks to save the entered values.

The API is similar to that used for registering custom post types and taxonomies so it should be familiar territory.

NOTE: The plugin now requires WordPress 3.3+ (chiefly for the wysiwyg & datepicker fields)

Like what you see? Want more field types and features added? Get in touch or contribute on github

See “Other Notes” section for usage information

Download

Latest version: Download Custom Metadata v0.7.1 [zip]

Installation

  1. Install through the WordPress admin or upload the plugin folder to your /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Add the necessary code to register your custom groups and fields to your functions.php or plugin.
  4. Enjoy!

FAQ

Q. Why a code-based approach instead of a UI?
A. Because the UI thing has been done before. And this more closely aligns with the existing WordPress approach of registering new types of content (post types, taxonomies, etc.)

This is also a developer feature, aimed towards site builders. And real developers don’t need UIs ;)

(But really, though, the main benefit of this fact comes into play when you’re working with multiple environments, i.e. development/local, qa/staging, production. This approach makes it easy to replicate UIs and features without having to worry about database synchronization and other crazy things.)

For another really well-done, really powerful code-based plugin for managing custom fields, check out Easy Custom Fields and the Custom Metaboxes and Fields For WordPress Class.

Q. Why isn’t the function just `add_metadata_field`? Do you really need the stupid `x_`?
A. We’re being good and “namespacing” our public functions. You should too.

Changelog

0.7.1

  • fix a bug where non-image file upload path doesn’t get inserted into the input when clicking Insert into Post from the media manager
  • add ‘editor’ and ‘richtext’ as synonyms of ‘wysiwyg’ field type

0.7

  • added the ability to have readonly fields with the new readonly paramater

0.6

  • note: the plugin now requires WordPress 3.3+ (chiefly for the wysiwyg & datepicker fields)
  • update/clean-up the examples file
  • properly enqueue admin css for WP 3.3+
  • added a filter for the CUSTOM_METADATA_MANAGER_URL constant
  • fix fields not appearing when editing users in WP 3.3+ (props @FolioVision)
  • now passing the $value for a display_callback (props @FolioVision)
  • use the new wp_editor() function (since WP 3.3+) instead of the_editor() (now deprecated)
  • wysiwyg fields are no longer cloneable (may be revisited in a future version)
  • note: metaboxes that have a wysiwyg field will break when moved, this is not a bug per-se (may be revisited in a future version)
  • password fields are now cloneable
  • added filters for most of the plugin’s internal variables
  • now using WordPress’ built-in jQuery UI for the datepicker field
  • updated the screenshots
  • updated the instructions in readme.txt

0.5.7

  • pass additional params for display_callback

0.5.6

  • fix bugs with datepicker

0.5.5

  • remove all whitespace
  • fix some bugs with the tinymce field

0.5.4

  • fix display_callback for fields

0.5.3

  • removed php opening shorttags <? in favor of regular <?php tags, which caused parse errors on some servers

0.5.2

  • better tiny mce implementation and added html/visual switch
  • small css fixes and added inline documentation
  • moved DEFINEs in to admin_init() so that they can be filtered more easily

0.5.1

  • Bug fix with group context on add meta box
  • Remove few lines of old code left-over from 0.4

0.5

  • Making the changes from 0.4 public
  • Removed ability to generate option pages; after further consideration this is out of scope for this project
  • Removed attachment_list field, useless
  • Dates now save as unix timestamp
  • Taxonomy fields now save as both a custom field and as their proper taxonomy (will consider adding the ability to enable/disable this in a future version)
  • Multiplied fields no longer save as a serialized array, instead they save as multiple metadata with the same key (metadata api supports multiples!) – remember to set the last param to false to get multiple values.
  • NOTE: currently multiplied fields will display out of order after saving, however this should not affect anything else other than the admin, should be fixed soon
  • Other small improvements

0.4

  • Enhanced the code which generates the different field types
  • Added new types: password, upload, wysiwyg, datepicker, taxonomy_select, taxonomy_radio, attachment_list
  • Added field multiplication ability
  • Metadata is now deleted if a value is empty
  • Can now also generate option pages which use a metabox interface

0.3

  • Can now limit or exclude fields or groups from specific ids
  • Added updated screenshots and new code samples!
  • Bug fix: the custom display examples weren’t working well
  • Bug fix: fields not showing on “Add New” page. Thanks Jan Fabry!
  • Bug fix: fields not showing on “My Profile” page. Thanks Mike Tew!

0.2

  • Added a textarea field type
  • Added support for comments (you can now specify comments as an object type)
  • Added basic styling for fields so that they look nice

0.1

  • Initial release

9 thoughts on “Custom Metadata

  1. I found this plugin is very useful, except one thing, how can i use multiple text input with fieldCustomList1_display function, instead of just one textbox

    hope to receive your answer

  2. Hi,
    I am quite a newbie. I installed the plugin. I added to “function.php” in my theme the line x_add_metadata_field( ‘Numero’, ‘post’ );

    And tried to write a post , hoping to see a new box titled “number” somewhere on the screen.

    But I see nothing.

    HAve I understood the purpose of the plugin ? What do I get wrong ?

  3. Big thanks for a really good plugin. There’s not that much pure developer oriented plugins out there and your Custom Metadata is very helpful. I hope you will follow your to-do list because additional field types and custom validation will be essential! Keep great work! :)

  4. Hi, there. I am using your plugin and it’s very usefull. But I have a bit headache finding a solution for a particular case. I added a custom “textarea” field to my users where I enable tinymce. It work well but the field is sanitized and i got all and removed. Do you think it would be possible to introduce an option to disable sanitizing for a give field (when adding it with x_add_metadata_field)

    or could i use a hook to do it ? (I am not really familiar with hooks yet)

    thx

    • Well sorry for disturbing i found a solution with sanitize_callback just strangely all are replaced before the sanitize_callback. i am investigation

  5. where the hell can i view the fields? i dont see them anywhere. i entered this code into functions.php but dont see anything in my wordpress dashboard or in users.

    /*————————————————*/
    /*—————–[CUSTOM-USER-META-DATA]————————*/
    /*————————————————*/
    $args_x_user_twitter = array(
    ‘group’ => ‘x_social_group’ // The slug of group the field should be added to. This needs to be registered with x_add_metadata_group first.
    , ‘field_type’ => ‘text’ // The type of field; possible values: text, checkbox, radio, select
    , ‘label’ => ‘Twitter’ // Label for the field
    , ‘description’ => ‘Twitter link’ // Description of the field, displayed below the input
    );

    $args_x_user_facebook = array(
    ‘group’ => ‘x_social_group’ // The slug of group the field should be added to. This needs to be registered with x_add_metadata_group first.
    , ‘field_type’ => ‘text’ // The type of field; possible values: text, checkbox, radio, select
    , ‘label’ => ‘Facebook’ // Label for the field
    , ‘description’ => ‘Facebook link’ // Description of the field, displayed below the input
    );

    add_action( ‘admin_init’, ‘my_theme_init_custom_fields’ );

    function my_theme_ainit_custom_fields() {
    if( function_exists( ‘x_add_metadata_field’ ) && function_exists( ‘x_add_metadata_group’ ) ) {
    x_add_metadata_group( ‘x_social_group’, ‘user’, array( ‘label’ => ‘User Social Group’));
    x_add_metadata_field( ‘x_user_twitter’, ‘user’, $args_x_user_twitter );
    x_add_metadata_field( ‘x_user_facebook’, ‘user’, $args_x_user_facebook );
    }
    }

  6. Like your plugin very much. Not sure I understand what Multiplied fields are and how to take advantage of them in your latest update. If you have time please explain. Thanks

Leave a Reply