Registering Configurations

Registering Configurations with Pods is possible through file-based or code-based registration.

You can register Pods, Groups, and Fields through code and now through file-based configurations in Pods 2.9+.

Registering Pods with JSON/YML files

Pods allows you to register configurations through JSON/YML files. You can also export your configurations to JSON using the Migrate Packages component in Pods itself.

Simply export the Pods you would like and download the JSON file by going to Pods Admin > Import/Export Packages. Then place your file in any of the following locations below:

  • your-theme/pods.json
    • This file can include Pods, Templates, or Pages
  • your-theme/pods/pods.json
    • This file can include Pods
  • your-theme/pods/templates.json
    • This file can include Pods Templates
  • your-theme/pods/pages.json
    • This file can include Pods Pages
  • your-theme/pods.yml
    • This file can include Pods, Templates, or Pages
  • your-theme/pods/pods.yml
    • This file can include Pods
  • your-theme/pods/templates.yml
    • This file can include Pods Templates
  • your-theme/pods/pages.yml
    • This file can include Pods Pages

Support for configuration file locations includes the current theme and parent theme (if you have a child theme).

File Format

The JSON file matches the Pods package format (Migrate Packages component). Every JSON/YML file should continue to have the root “pods” or “templates” array as that is used to parse that specific information. This allows you to add whatever extra meta information you would like to your JSON/YML files that helps you identify it or keep track of the version/date on your own.

Example Files

Example pods.json

Here’s an example of a pods.json configuration file:

{
  "pods": [
    {
      "name": "book_author",
      "label": "Authors",
      "label_singular": "Author",
      "type": "post_type",
      "storage": "meta",
      "public": 1,
      "groups": [
        {
          "name": "more_fields",
          "label": "More Fields",
          "fields": [
            {
              "name": "books",
              "label": "Books",
              "type": "pick",
              "pick_object": "post_type",
              "pick_val": "book",
              "pick_format_type": "multi",
              "pick_format_multi": "list"
            }
          ]
        }
      ]
    },
    {
      "name": "book",
      "label": "Books",
      "label_singular": "Book",
      "type": "post_type",
      "storage": "meta",
      "public": 1,
      "fields": [
        {
          "name": "isbn",
          "label": "ISBN",
          "type": "text"
        }
      ]
    },
    {
      "name": "chapter",
      "label": "Chapters",
      "label_singular": "Chapter",
      "type": "post_type",
      "storage": "meta",
      "public": 1,
      "fields": [
        {
          "name": "book",
          "label": "Book",
          "type": "pick",
          "pick_object": "post_type",
          "pick_val": "book",
          "pick_format_type": "single",
          "pick_format_single": "list"
        }
      ]
    }
  ]
}

Example pods.yml

Here’s an example of a pods.yml configuration file:

---
pods:
- name: book_author
  label: Authors
  label_singular: Author
  type: post_type
  storage: meta
  public: 1
  groups:
  - name: more_fields
    label: More Fields
    fields:
    - name: books
      label: Books
      type: pick
      pick_object: post_type
      pick_val: book
      pick_format_type: multi
      pick_format_multi: list
- name: book
  label: Books
  label_singular: Book
  type: post_type
  storage: meta
  public: 1
  fields:
  - name: isbn
    label: ISBN
    type: text
- name: chapter
  label: Chapters
  label_singular: Chapter
  type: post_type
  storage: meta
  public: 1
  fields:
  - name: book
    label: Book
    type: pick
    pick_object: post_type
    pick_val: book
    pick_format_type: single
    pick_format_single: list

Custom files and paths

Pods also has support for you to register custom files or paths for your own plugins.

Register a custom config file

This config file can contain Pods, Templates, or Pages.

<?php

/**
 * Register the Pods configuration file.
 */
function register_my_pods_config_file() {
	// Register a custom pods.json file.
	pods_register_config_file( 'path/to/your/plugin/pods.json' );

	// Register a custom pods.yml file.
	pods_register_config_file( 'path/to/your/plugin/pods.yml', 'yml' );
}

add_action( 'init', 'register_my_pods_config_file' );

Register a custom config path

Custom paths must be within ABSPATH or they will not be accepted.

<?php

/**
 * Register the Pods configuration path.
 */
function register_my_pods_config_path() {
	pods_register_config_path( 'path/to/your/plugin' );
}

add_action( 'init', 'register_my_pods_config_path' );

Registering Pods with PHP

Pods allows you to register configurations through code. You can also export your configurations to code using the free Pods Export to Code Add-On.

<?php

/**
 * Register the Pods configurations.
 */
function register_my_pods_config_29738251() {
	$pod = [
		'name'           => 'book_author',
		'label'          => 'Authors',
		'description'    => '',
		'type'           => 'post_type',
		'storage'        => 'meta',
		'label_singular' => 'Author',
		'public'         => '1',
	];

	pods_register_type( $pod['type'], $pod['name'], $pod );

	$group = [
		'name'        => 'more_fields',
		'label'       => 'More Fields',
		'description' => '',
		'weight'      => 0,
	];

	$group_fields = [
		'books' => [
			'name'              => 'books',
			'label'             => 'Books',
			'description'       => '',
			'weight'            => 0,
			'type'              => 'pick',
			'pick_object'       => 'post_type',
			'pick_val'          => 'book',
			'pick_format_type'  => 'multi',
			'pick_format_multi' => 'list',
		],
	];

	pods_register_group( $group, $pod['name'], $group_fields );

	$pod = [
		'name'           => 'book',
		'label'          => 'Books',
		'description'    => '',
		'type'           => 'post_type',
		'storage'        => 'meta',
		'label_singular' => 'Book',
		'public'         => '1',
	];

	pods_register_type( $pod['type'], $pod['name'], $pod );

	$group = [
		'name'        => 'more_fields',
		'label'       => 'More Fields',
		'description' => '',
		'weight'      => 0,
	];

	$group_fields = [
		'isbn' => [
			'name'        => 'isbn',
			'label'       => 'ISBN',
			'description' => '',
			'weight'      => 0,
			'type'        => 'text',
		],
	];

	pods_register_group( $group, $pod['name'], $group_fields );

	$pod = [
		'name'           => 'chapter',
		'label'          => 'Chapters',
		'description'    => '',
		'type'           => 'post_type',
		'storage'        => 'meta',
		'label_singular' => 'Chapter',
		'public'         => '1',
	];

	pods_register_type( $pod['type'], $pod['name'], $pod );

	$group = [
		'name'        => 'more_fields',
		'label'       => 'More Fields',
		'description' => '',
		'weight'      => 0,
	];

	$group_fields = [
		'book' => [
			'name'               => 'book',
			'label'              => 'Book',
			'description'        => '',
			'weight'             => 0,
			'type'               => 'pick',
			'pick_object'        => 'post_type',
			'pick_val'           => 'book',
			'pick_format_type'   => 'single',
			'pick_format_single' => 'list',
		],
	];

	pods_register_group( $group, $pod['name'], $group_fields );
}

add_action( 'init', 'register_my_pods_config_29738251' );

Other Helpful Documentation on Code Reference

Action Hook Reference

Field Functions

Field handling with Pods

Filter Reference

General Functions

Media Functions

Media handling functions in Pods

Pods Blocks API

Pods 2.8 introduces a new API for creating blocks with PHP.

Pods DFV JS API

The DFV JS API allows you to interact with the forms that Pods displays.

Pods REST API Endpoints

The Pods Admin REST API Endpoints for managing configurations.

Pods WP-CLI Commands

How to use the Pods CLI to access wp pods and wp pods api

pods_api()

We are working hard on our new code reference site. Until then this section will remain unavailable. Thank you for your patience.

pods_ui()

Easily create content admin screens with in-depth customization.

pods()

Set up the Pods class object for a specific pod.

WPGraphQL Integration

The WPGraphQL integration allows Pods content types and their fields to be discoverable by the WPGraphQL plugin.