Custom Post Types announced in WordPress 3.0 brought back popularity to WordPress sites among clients and developers. WordPress is quite easy for newbies in web and it’s very easy and self-explanatory for content editors. With Custom Post Types we can improve standard functionality in times and add more sections (like Posts or Pages).
Another cool feature which gives you an option to improve your WordPress base is WordPress Custom Fields. However it’s hard to use for non-technical person. We tried to use different plugins, which improve the usability of standard custom fields (like Custom Fields), however we found a lot of major bugs there, it used a lot of memory etc.
“Just Custom Fields for WordPress“. This plugin adds custom fields for standard and custom post types in WordPress. After installation you will see simple settings page which is self-explanatory to use
- Download, unzip and upload to your WordPress plugins directory
- Activate the plugin within your WordPress Administration Backend
- Go to Settings > Just Custom Fields
- Choose Post Type (Standard/Custom) where you would like to edit custom fields
- Create Fieldset
- Add fields to the fieldset.
On this screenshot you can see settings page for a “Page” post type. You can create fieldsets and fields inside of it. This page uses WordPress AJAX API, so it updates without any redirects and editing rather quickly.
You can create field with one of types below:
- Input text: usual single-line text box
- Select: usual dropdown list
- Select Multiple: area which allows you to select multiple options from the list
- Checkbox: you can add one or multiple checkboxes
- Textarea: multi-line text field. You can also enable WordPress editor for this field
- Datepicker: input field with calendar popup to choose a date
- Simple media: use this field to create image or file container
- Collection: with help of this field you can create multiple groups of fields, which can be repeated number of times. You can add other field to this collection. (For example you can create your own Gallery, by adding Simple media for image, Input Text for Title, and Textarea for description).
- Related Content: using this field allows you to link other post types with your post
The following screenshot illustrates how a fieldset will look on a post edit page. There are usual text box, select box, file upload and Collection with Simple media field (as you can see you can upload many images in this way).
WordPress developers also find this plugin very useful. Cause it’s very easy to add their own components and custom fields with their own plugins and even themes using some new hooks. For more details you are welcome to check readme.txt file from the plugin package.
Using WordPress Shortcode functions
If you are not familiar with Post meta API we recommend to use plugin shortcodes, presented in version 2.2.
You can find usage instructions at post edit page under help popup. Just insert code example into your template and it will print the value for you.
Shortcode adds a lot of HTML wrappers for frontend developers to be able to style/position value for any needs.
Working with Post Meta directly
For skilled WordPress developers we recommend to use native post meta functions such as:
Let’s show some examples. For example we create 3 custom fields for the Page with such slugs:
- _price (Input Text)
- _features (Checkboxes/multiple)
- _author_avatar (Simple Media / image)
To get values in templates you need to place the following lines of code inside the loop functions:
$price = get_post_meta(get_the_ID(), '_price', true); // we get value from input text $avatar_id = get_post_meta(get_the_ID(), '_author_avatar', true); // we get image attachment ID $features = get_post_meta(get_the_ID(), '_features', true); // we get array of checked checkboxes
Now when you have variables with the data you can print them in the template. For example like this:
Price: echo $price; Features: foreach($features as $feature) echo $feature.','; Avatar: wp_get_attachment_image($avatar_id, ‘thumbnail’);
You can read more about using custom fields on Codex.WordPress.org: Custom Fields or search more information in google. There are a lot of examples on different sites how to use WordPress custom fields. Our plugin just makes easy interface to edit them in administration panel, and you can use all built-in WordPress functions for custom fields.
This plugin is available for downloading in official WordPress repository: