Skip to content

Updates the documentation: Adds tutorials on creating post types, custom fields, taxonomies, and options pages, and improves guidance on the relationship between post types, taxonomies, and custom fields. #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions docs/tutorials/first-custom-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Creating Your First Custom Field

A beginner-friendly guide to adding custom fields using Secure Custom Fields (SCF).

**What is a custom field?**

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.

## Prerequisites

- SCF installed and activated
- A post type (default or custom) where you'll attach your fields
- Administrator access to WordPress

You can learn more about WordPress basics here:

- [Theme Basics](https://developer.wordpress.org/themes/basics/)
- [Plugin Basics](https://developer.wordpress.org/plugins/plugin-basics/)

## 1. Access the Admin Panel

- Go to **Secure Custom Fields → Field Groups** in your WordPress admin menu.
- Click **"Add New"** to create a new group of fields.

## 2. Basic Configuration

### Field Group Title

Give your field group a descriptive name, like `Movie Details` or `Product Specs`.

### Location Rules

Choose where this group should appear. For example:

- Post type is equal to `Movie`
- Page template is `Product Page`

This ensures your fields appear only where you need them.

**Note:** This fine-grained control allows you to define SCF fields once and reuse them across different post types, templates, or components.

### Active

Make sure the field group is set to **Active** so it appears in the editor.

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

## 3. Adding Fields

Click **"Add Field"** to create your first field, configure:

### Minimum required settings

To create a functional custom field, you only need to define the following in the **General** tab:

- **Field Type** (e.g., Text, Image, Select): Defines the kind of input
- **Field Label**: The name shown in the editor
- **Field Name**: A unique, code-friendly identifier (no spaces; dashes and underscores allowed)

For example, you could create fields like:

- **"Movie Title"** (`movie_title`) — a text field to store the name of the movie
- **"Director"** (`director`) — another text field to store the director's name
- **"Release Year"** (`release_year`) — a number field to store the release year

> **Note:** All other settings are optional and provide extra control or visual customization.

---

### 🔧 Full settings overview by tab

### General

Basic field definition and default behavior:

- **Field Type**
- **Field Label**
- **Field Name**
- **Default Value**

### Validation

Rules to control what values are allowed:

- **Required**
- **Minimum / Maximum Values**
- **Allowed Characters / Pattern**
- **Custom Validation Message**

### Presentation

Controls how the field appears in the editor:

- **Placeholder Text**
- **Instructions**
- **Wrapper Attributes**
- **Hide Label**

### Conditional Logic

Display logic to control field visibility:

- **Enable Conditions**
- **Condition Rules**

> **Note:** Not all options appear for every field type. Each field may expose different settings depending on its nature.

---

Repeat this process for as many fields as needed.

## 4. Testing

- Go to a post of the type you've targeted with the field group.
- You should now see your custom fields below the content editor.
- Fill in test data and save the post.
- Confirm the fields save and appear as expected.

## For Developers

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

You can learn more about WordPress native custom fields here:

👉 [WordPress Native Custom Fields](https://developer.wordpress.org/plugins/metadata/custom-fields/)

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.
96 changes: 96 additions & 0 deletions docs/tutorials/first-options-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Creating Your First Options Page

A step-by-step guide to building a global settings page using Secure Custom Fields (SCF).

**What is an options page?**

An options page is a custom admin screen where you can store site-wide settings that are not linked to individual posts, pages, or taxonomies. These values are useful for things like contact details, configuration values, or custom messages that may appear across your theme.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

across your theme

How are these options related to themes? What would be an example?


## Prerequisites

- SCF (Secure Custom Fields) installed and activated
- Administrator access to WordPress
- Basic understanding of WordPress admin and SCF interface

You can learn more about WordPress basics here:

- [Theme Basics](https://developer.wordpress.org/themes/basics/)
- [Plugin Basics](https://developer.wordpress.org/plugins/plugin-basics/)

## 1. Access the Admin Panel

- Go to **Secure Custom Fields → Options Pages** in your WordPress admin sidebar.
- Click **"Add New"** to create your options page.

## 2. Basic Configuration

Set up the following fields to define the behavior and placement of your options page:

### Basic Settings Panel

- **Page Title**: The title displayed at the top of the options page (e.g., `Site Settings`).
- **Menu Slug**: A unique identifier for the page URL (e.g., `site-settings`).
- **Parent Page**: Choose `No Parent` to create a standalone page or select a parent if it should appear as a submenu item.
- **Advanced Configuration**: Enable to access additional options.

### Advanced Settings Panel

#### Visibility

- **Menu Title**: Label that appears in the WordPress admin menu.
- **Menu Icon**: Choose an icon from Dashicons or upload a custom SVG or URL.
- **Menu Position**: Controls the position of the item in the admin sidebar.
- **Redirect to Child Page**: If enabled, this page redirects to its first child page automatically.

#### Description

- **Description**: A short description to help explain the purpose of this options page.

#### Labels

- **Update Button Label**: Text shown on the submit button (e.g., `Update Settings`).
- **Updated Message**: Message displayed after saving the options.

#### Permissions

- **Capability**: Required capability to view/edit this page (default is `edit_posts`).

#### Data Storage

- **Storage Location**: Choose whether to store the data in the options table (default) or bind it to a specific post, user, or term.
- **Custom Storage**: Use a specific post ID (e.g., `123`) or context string (e.g., `user_1`).
- **Autoload Options**: Enable to automatically load these values when WordPress initializes — useful for performance.

Click **Save** to create the options page. Once saved, you can start adding custom fields as needed.

## 3. Adding Fields

Add fields just like you would for any post type or taxonomy.

### Common Fields to Add:

- `company_name` — Company name (text)
- `support_email` — Support contact email (email)
- `emergency_alert_message` — Site-wide notice (textarea)
- `global_logo` — Logo image (image upload)

Each of these fields will be accessible from any page or template.

## Next Steps

- Use options fields to manage design elements like footer text or banners
- Reference options globally to reduce repeated settings in CPTs or pages
- Combine with conditional logic to enable dynamic site-wide behavior

## For Developers

Options pages provide a clean way to centralize configuration. In more advanced implementations, you can:

- Register multiple options pages for different sections (e.g., Branding, API Keys)
- Use `get_option()` if working outside the SCF context
- Integrate with theme customizers or other plugin logic

Secure Custom Fields simplifies this process, but WordPress also offers a native way to register and manage options pages through the **Settings API**. This allows full control over settings registration, sanitization, and display via code.

👉 Learn more about the WordPress Settings API:
[https://developer.wordpress.org/plugins/settings/settings-api/](https://developer.wordpress.org/plugins/settings/settings-api/)
150 changes: 127 additions & 23 deletions docs/tutorials/first-post-type.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,140 @@
# Creating Your First Post Type

A step-by-step guide to creating a custom post type using Secure Custom Fields.
A step-by-step guide to creating a custom post type using Secure Custom Fields (SCF).

**What is a custom post type?**

In WordPress, a custom post type (CPT) is a content type like posts and pages, but customized to suit your specific needs. You can use CPTs to manage products, portfolios, testimonials, events, vehicles, and more—essentially any type of structured content that needs its own menu and fields.

## Prerequisites

- SCF installed and activated
- Administrator access to WordPress
- Basic understanding of WordPress concepts
- SCF installed and activated
- Administrator access to WordPress
- Basic understanding of WordPress concepts

You can learn more about WordPress basics here:

- [Theme Basics](https://developer.wordpress.org/themes/basics/)
- [Plugin Basics](https://developer.wordpress.org/plugins/plugin-basics/)

## 1. Access the Admin Panel

To begin creating your custom post type:

- Go to **Secure Custom Fields → Post Types** in your WordPress admin menu.
- Click the **"Add New"** button to open the creation form.

## 2. Basic Configuration

These fields help you define how your post type will appear and behave:

### Plural Label \*

This is the name that will appear in the admin sidebar. For example, `Movies`.

### Singular Label \*

Used for individual entries. Example: `Movie`.

### Post Type Key \*

A technical identifier for WordPress to recognize this post type. Use lowercase letters and underscores only. Max 20 characters. Example: `movie`.

### Taxonomies

Choose existing taxonomies like **category** or **tags** if you want to group or filter your content. You can also select custom ones like **Brand** or **Color**.

### Public

Choose **Yes** to make your post type visible on the website and admin area. Choose **No** to keep it private.

### Hierarchical

Set to **Yes** if you want your items to be nested (like pages). Set to **No** for a flat list (like blog posts).

### Advanced Configuration

Enable this to unlock more advanced options, useful when you need more control over how your post type works.

## 3. Advanced Settings

These options let you customize deeper behaviors and labels.

## Steps
### Supports

1. **Access the Admin Panel**
- Navigate to Custom Fields → Post Types
- Click "Add New"
Select which features to enable when editing a post, such as:

2. **Basic Configuration**
- Enter a descriptive name
- Configure labels
- Set visibility options
- **Title**: Adds a title field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed the spaces after the hyphen; is there any linting rule that requires this?

- **Editor**: Main content box
- **Featured Image**: Allow image upload
- **Comments**, **Author**, **Excerpt**, etc.

3. **Advanced Settings**
- Configure permalinks
- Set up taxonomies
- Define capabilities
### Description

4. **Testing**
- Save your post type
- Create a test post
- View on front end
A short explanation of what this post type is about. Helpful for organization.

### Active

Make sure this is set to **Yes** so your post type is registered and usable.

### Labels

These are the texts that WordPress shows throughout the dashboard. For example:

- **Menu Name**: What appears in the sidebar
- **Add New Item**: Button to create a new entry
- **Edit Item**, **View Item**, **Search Items**, etc.
You can keep the default labels or customize them to your liking.

### Visibility Options

Control where your post type appears in the admin and site:

- Show in dashboard menu
- Show in admin bar
- Show in appearance menus

### Menu Icon and Position

Choose an icon for your post type from the WordPress Dashicons set. Optionally, set its position in the sidebar.

### Permalinks and URLs

You can define how URLs will look for your post type:

- **Slug**: A custom word for your URL (e.g., `/movie/`)
- Enable archive and pagination
- Optionally include RSS feeds

### Permissions

If needed, you can assign custom capabilities like `edit_movie` or `delete_movies`. Useful for advanced role control.

### REST API Settings

Enable this if you plan to use the post type with the block editor or external tools.

- You can customize the API route, namespace, or controller class if needed.

## 4. Testing

Once everything is set up:

- Click **Save** to register your post type.
- Go to the WordPress dashboard menu where your new post type now appears.
- Click **Add New** and create a test entry.
- Visit your website and check that it appears correctly on the frontend.

## Next Steps

- Add custom fields to your post type
- Configure archive displays
- Set up custom taxonomies
- Add custom fields to your post type via Secure Custom Fields
- Configure how archives and single templates are displayed in your theme
- Set up or register your own taxonomies for more organization

## For Developers

If you're a developer and prefer to register custom post types using code instead of the admin interface, you can refer to the official WordPress documentation:

[How to Create Custom Post Types with Code](https://developer.wordpress.org/plugins/post-types/)

This guide includes examples and explanations on using `register_post_type()` and other related functions.
Loading
Loading