Zum Inhalt springen
nnhelpers for WordPress

nnhelpers for WordPress

A toolbox-plugin with a huge collection of one-liners to drastically speed up your plugin-development

About

  • What is nnhelpers?

Getting started

  • Installation
  • Creating a plugin

Custom Post Types (CPT)

  • Creating a Custom Post Type (CPT)
  • Adding forms and fields to your CPT
  • Adding forms and fields to WordPress posts
  • CPT – field types and configurations

Custom Widgets and Blocks

  • Creating a custom widget for Elementor

Basic Concepts

  • QueryBuilder
  • Model
  • Repository
  • Fluid Templates
  • Creating custom ViewHelpers
  • Home
  • Docs
  • Custom Post Types (CPT)
  • Adding forms and fields to WordPress posts

Adding forms and fields to WordPress posts

Table of Contents
  • How to add additional / custom fields to the default WordPress Posts
    • File: Configuration/CPT/post.php
    • Convention over Configuration
Table of Content

How to add additional / custom fields to the default WordPress Posts #

This basically works the same way you add forms and fields to your custom post type.

The only difference: You add 'extends' => ['post'] to the coniguration array.

This way you can add custom forms and fields to the standard WordPress-posts. Following the WordPress tradition, this data will be stored in the table postmeta of your database.

Let's add an input-field "www" that will appear on the right column when editing a posts in the backend.

File: Configuration/CPT/post.php #

<?php

$myForm = [
    'ctrl' => [
        'title'   => 'Additional Infos',
        'position' => 'right,bottom',
    ],
    'columns' => [
        'www' => [
            'label' => 'Website',
            'config' => [
                'type' => 'input',
                'size' => 30,
                'max' => 255,
            ],
        ],
    ],
];

return [
    'extends' => ['post'],
    'forms' => [$myForm]
];

Done.

When editing a WordPress post in the backend, you now will see a new form on the right bottom column with an input field.

nnhelpers takes care of all the complicated things like rendering the form-fields, adding a nonce for security and writing / updating the data in the postmeta-database table.

Convention over Configuration #

The form-data will be saved as postmeta-data using the convention _{pluginname}_{fieldname}.

In the example above, the configuration is inside a plugin called example and we have defined a fields with the name www. These will be saved in the table postmeta with the meta_key _example_www.

Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Still stuck? How can we help?

How can we help?

Updated on 3. Juli 2022
Adding forms and fields to your CPTCPT – field types and configurations

Powered by BetterDocs

Table of Contents
  • How to add additional / custom fields to the default WordPress Posts
    • File: Configuration/CPT/post.php
    • Convention over Configuration
nnhelpers for WordPress
Mit Stolz präsentiert von WordPress.