|
| 1 | +# Creating Your First Custom Field |
| 2 | + |
| 3 | +A beginner-friendly guide to adding custom fields using Secure Custom Fields (SCF). |
| 4 | + |
| 5 | +**What is a custom field?** |
| 6 | + |
| 7 | +Custom fields let you add structured data to your content. With SCF, you can attach fields like text inputs, selects, image uploads, and more to your posts, pages, or custom post types. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- SCF installed and activated |
| 12 | +- A post type (default or custom) where you'll attach your fields |
| 13 | +- Administrator access to WordPress |
| 14 | + |
| 15 | +You can learn more about WordPress basics here: |
| 16 | + |
| 17 | +- [Theme Basics](https://developer.wordpress.org/themes/basics/) |
| 18 | +- [Plugin Basics](https://developer.wordpress.org/plugins/plugin-basics/) |
| 19 | + |
| 20 | +## 1. Access the Admin Panel |
| 21 | + |
| 22 | +- Go to **SCF → Field Groups** in your WordPress admin menu. |
| 23 | +- Click **"Add New"** to create a new group of fields. |
| 24 | + |
| 25 | +## 2. Basic Configuration |
| 26 | + |
| 27 | +### Field Group Title |
| 28 | + |
| 29 | +Give your field group a descriptive name, like `Movie Details` or `Product Specs`. |
| 30 | + |
| 31 | +### Location Rules |
| 32 | + |
| 33 | +Choose where this group should appear. For example: |
| 34 | + |
| 35 | +- Post type is equal to `Movie` |
| 36 | +- Page template is `Product Page` |
| 37 | + |
| 38 | +This ensures your fields appear only where you need them. |
| 39 | + |
| 40 | +**Note:** This fine-grained control allows you to define SCF fields once and reuse them across different post types, templates, or components. |
| 41 | + |
| 42 | +### Active |
| 43 | + |
| 44 | +Make sure the field group is set to **Active** so it appears in the editor. |
| 45 | + |
| 46 | +**Note:** Some features require the field group to be **enabled** and **exposed via the REST API**. To future-proof your configuration, we recommend setting **Show in REST** to `true` when creating your field groups. |
| 47 | + |
| 48 | +## 3. Adding Fields |
| 49 | + |
| 50 | +To start building your custom field group, click the **"Add Field"** button. |
| 51 | + |
| 52 | +Each field requires at least a few basic settings to work correctly. All other options are optional and can be used to improve the user experience in the editor. |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +### Minimum Required Settings |
| 57 | + |
| 58 | +In the **General** tab, you must define the following: |
| 59 | + |
| 60 | +- **Field Type** |
| 61 | + Specifies what kind of data the field will store (e.g., Text, Image, Number, Select). |
| 62 | + |
| 63 | +- **Field Label** |
| 64 | + The human-readable name shown in the editor (e.g., “Movie Title”). |
| 65 | + |
| 66 | +- **Field Name** |
| 67 | + A unique identifier used in the code (lowercase, no spaces; underscores or dashes allowed). |
| 68 | + |
| 69 | +#### 📌 Example: Movie Fields |
| 70 | + |
| 71 | +Let’s say you want to create a group of fields for movie entries. Here's how you could configure it: |
| 72 | + |
| 73 | +| Field Label | Field Name | Field Type | Description | |
| 74 | +|------------------|------------------|------------|------------------------------------------| |
| 75 | +| Movie Title | `movie_title` | Text | Stores the name of the movie | |
| 76 | +| Director | `director` | Text | Stores the name of the director | |
| 77 | +| Release Year | `release_year` | Number | Stores the year the movie was released | |
| 78 | +| Poster Image | `poster` | Image | Upload an image file for the movie poster | |
| 79 | + |
| 80 | +> 💡 These fields would be added one by one using the **Add Field** button, and each configured in the field editor panel. |
| 81 | +
|
| 82 | +--- |
| 83 | + |
| 84 | +## General Settings |
| 85 | + |
| 86 | +Defines the field behavior and how it is stored: |
| 87 | + |
| 88 | +- **Field Type** |
| 89 | + What kind of input this field accepts (text, image, number, etc.). |
| 90 | + |
| 91 | +- **Field Label** |
| 92 | + The label shown to the user in the WordPress editor. |
| 93 | + |
| 94 | +- **Field Name** |
| 95 | + The code-safe name used to retrieve the value in your templates or plugins. |
| 96 | + |
| 97 | +- **Default Value** |
| 98 | + A pre-filled value shown if no value is entered. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Validation Settings |
| 103 | + |
| 104 | +Used to restrict and control the kind of data that can be entered: |
| 105 | + |
| 106 | +- **Required** |
| 107 | + Makes the field mandatory. |
| 108 | + |
| 109 | +- **Minimum / Maximum Values** |
| 110 | + For numeric or character-based fields. Useful for fields like `release_year`. |
| 111 | + |
| 112 | +- **Allowed Characters / Pattern** |
| 113 | + Use a regular expression to restrict input format (e.g., only digits). |
| 114 | + |
| 115 | +- **Custom Validation Message** |
| 116 | + Message shown if validation fails (e.g., “Please enter a valid year”). |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## Presentation Settings |
| 121 | + |
| 122 | +Controls the visual appearance of the field in the editor: |
| 123 | + |
| 124 | +- **Placeholder Text** |
| 125 | + Example text shown inside the field input. |
| 126 | + |
| 127 | +- **Instructions** |
| 128 | + Helper text shown below the field to guide users. |
| 129 | + |
| 130 | +- **Wrapper Attributes** |
| 131 | + Custom HTML attributes like class or ID for styling or JavaScript. |
| 132 | + |
| 133 | +- **Hide Label** |
| 134 | + Option to hide the field label (not recommended unless styled separately). |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Conditional Logic |
| 139 | + |
| 140 | +Used to show or hide fields based on the value of other fields: |
| 141 | + |
| 142 | +- **Enable Conditions** |
| 143 | + Activate conditional display rules for this field. |
| 144 | + |
| 145 | +- **Condition Rules** |
| 146 | + Example: only show the “Director” field if “Content Type” equals “Movie”. |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +> ⚠️ **Note:** Some settings may not be available for all field types. The options shown will adapt depending on the field you're configuring. |
| 151 | +
|
| 152 | +--- |
| 153 | + |
| 154 | +### Final Step |
| 155 | + |
| 156 | +Repeat this process to add as many fields as needed to your group. Once ready, you can assign this field group to a post type and start entering content! |
| 157 | + |
| 158 | +## For Developers |
| 159 | + |
| 160 | +While Secure Custom Fields makes it easier to manage and display custom fields with a user-friendly interface, WordPress also includes native support for custom fields that can be managed programmatically using functions like `get_post_meta()` and `add_post_meta()`. |
| 161 | + |
| 162 | +You can learn more about WordPress native custom fields here: |
| 163 | + |
| 164 | +👉 [WordPress Native Custom Fields](https://developer.wordpress.org/plugins/metadata/custom-fields/) |
| 165 | + |
| 166 | +To access custom field values in your theme or plugin, use SCF functions you can learn more about SCF’s developer API in their official documentation. |
0 commit comments