admin-plugins author calendar category facebook post rss search twitter star star-half star-empty

Tidy Repo

The best & most reliable WordPress plugins

Free Custom Field Suite

Custom Field Suite

Plugin Author: Matt Gibbs

Jay Hoffmann

August 20, 2014 (modified on May 24, 2018)

Page

Advanced Custom Fields was one of the first plugins I ever reviewed on this site. But if you’re looking for a slightly more paired down custom field plugin, then look no further then Custom Field Suite.

What’s It Do?

Custom Field Suite allows you to easily add groups of custom fields to your posts and pages with several different types to choose from (text, date picker, users and more). The plugin features an easy to understand API for displaying the fields on your site, all of which is fairly standard in a custom field plugin generally. But Custom Field Suite also has a few unique features, such as the ability to add a front-end editing form for the title, content and custom fields anywhere on your site. You also have the ability to add custom validations, among a few other hooks, and save revisions of your custom field data. It lacks some of the robustness that other custom field plugins have integrated into their feature set, but if you are looking for something simple, extendable, and easy to use, it will probably be a good match.

How’s It Work?

Like many of the plugin’s featured on Tidy Repo, Custom Field Suite has a lot of options. I’ll only be giving an introduction here, but you can explore its documentation for examples of how to do just about anything. The first step is to install and activate it.

After you do, there will be a new menu item added to your admin panel labeled “Field Groups.” Go to Field Groups -> Field Groups and click the “Add New” link to get started. First, give your field group a title. Then, you can add your first field by clicking the “Add New Field” button. Each field that you create requires a “Label” and a “Name.” The former is what will be shown on posts and pages when users are entering custom field data. The latter is how it will be identified when you output the fields to the front-end of your site. More on that later.

Custom Field Suite layout

A listing of all current field groups

From the “Field Type” drop-down, select what kind of custom field you want to add. There are several options to choose from: Text, Textarea, WYSIWYG Editor, Date, Color, True / False, Select, Relationship, User, File Upload, Loop, and Tab. Most are fairly self-explanatory. For instance, the Text option will display a simple text field, the Select option will show a list of custom options as radio buttons, and the File Upload button will show a simple file upload field. The Relationship field allows you to add a field to a list of posts, pages, and attachments from your site. From there, users can select posts to associate with the current post, which you can link up however you want (a related content section for instance). The Loop field is simply a container that you can put several other fields inside. Users will be able to add multiple instances of this container, for anything you need to repeat (like a gallery).

Each custom field type has its own set of options. For each, however, you can select whether it is a required field or not, and most offer the option for a default value. I won’t get into the details of each field type here, but simply follow the instructions to customize the values, options, and parameters for each.

Custom Field Suite plugin settings

Set default values for your custom fields

Below this, you will see a “Placement Rules” section. This allows you to define where a field group will be displayed on the back-end. You can limit groups by Post Types, Individual Posts, User Roles, Taxonomy Terms and more. For each, simply enter in the names of the content that you want to include or exclude, then select “equals” or “is not” from the drop-down menu next to it. For instance, you can limit Post Types to pages by entering that in and selecting equals. When you do this, the custom fields will only appear in the post editor of the content types that you choose.

The last section is “Extras” where you can define the order you want the group to appear compared to other field groups you’ll create and choose whether it should appear below the post editor or in the sidebar. You can also check the box next to “Hide the content editor” to remove the main content editor from the post editor whenever the current field group is displayed. When you’re all finished setting up the plugin, click the “Publish” button.

Now, just visit the Post Editor of any post or page where you chose to place the field group. Below the main content editor (or in the sidebar) you will see a list of the fields that you have set up. For each, you can enter a value, and each is customized for the field type. The Date field, for instance, will show a simple calendar date picker. For any post you want to add these custom fields, simply fill them out and publish your post as you normally would.

Custom Field Suite in the post editor

In the post editor, you can easily add content to your custom fields

The last step is to actually output the custom field data on your site’s front-end. Custom Field Suite offers a simple API that allows you to do that. First, open up the template file for content type you want to add your custom field data too. The simplest way to output a value is the get() helper.

echo $cfs->get('field_name');

This will display the custom field’s content in it’s simplest form. If you want to output all the values of your custom fields at once, simply leave out the field name:

echo $cfs->get();

Several fields will have a list of items for you to show and will require you to set up a for each loop to display them. The Loop, Select, User, and Relationship field all fall into this category. For these, you will need to retrieve an array of IDs using the field name and then iterate through them. For a Loop container, for instance:

$loop = $cfs->get('loop_name');
foreach ( $loop as $row ) {
    echo $row['individual_field_name']; // a sub-field
}

Or for a Relationship field.

$values = $cfs->get('field_name');
foreach ($values as $post_id) {
    $the_post = get_post($post_id);
    echo $the_post->post_title;
}

The above example is very similar to how the User and Select fields work as well.

One useful feature that Custom Field Suite gives you is the form() helper. This allows you to add a front-end form to your templates where users can edit a post’s title, content and custom field data without having to visit the admin section of your site. To do this, simply add the form() method to your template files and pass in which content you want to be editable. If you, for instance, want to include the post’s content and title as well as custom fields, it would look like this:

echo $cfs->form(array(
    'post_id' => $post->ID,
    'post_title' => 'The Title',
    'post_content' => 'The Content',
));

If you pass in post_id as “false,” then the form will instead create a new post automatically. You can also choose to exclude certain fields, like this:

echo $cfs->form(array(
    'post_id' => false,
    'excluded_fields' => array('field_name_1', 'field_name_2')
));

Remember, this form will show up for any user, but only logged in users with post edit access will actually be able to submit the form. So, if you do choose to use it, make sure to include some sort of authentication or validation before showing the forms, so that every user doesn’t see it. The form function can be very handy if you want to be able to edit content on the fly, so check out the examples on its documentation page for more info.

This may be all you need to do. It will allow you to add custom field values to your posts and pages, and then output them anywhere in your template files. However, the API also gives you access to a few useful hooks to extend the plugin’s functionality and a couple of methods to programmatically update and save your custom field content. These allow you to perform custom validations, add data before saving an input, and pre-render fields. How to use these is a bit beyond the scope of this tutorial, but they are worth checking out.

Plugin Info
  • Downloads: 599,915+
  • Downloads trend (30d): +353.6%
  • Active installations: 50,000+
  • Rating:
  • Last Update: February 27th, 2024
  • Download Plugin for Free