Registering Custom Post Types in the WordPress Admin: Our CloudFest Hackathon Report - EMEL

Latest

EMEL

Monday, April 15, 2024

New

Registering Custom Post Types in the WordPress Admin: Our CloudFest Hackathon Report

Media Mamat Turbo April 15, 2024
With WordPress today you need to use custom code or a plugin to create a custom post type like "Book" or "Member." This is a popular need, and there are a variety of approaches; however, one challenge is that the end-user experience can be confu…
Read on blog or Reader
Site logo image WordPress.com News Read on blog or Reader

Registering Custom Post Types in the WordPress Admin: Our CloudFest Hackathon Report

Daniel Bachhuber

April 15

With WordPress today you need to use custom code or a plugin to create a custom post type like "Book" or "Member." This is a popular need, and there are a variety of approaches; however, one challenge is that the end-user experience can be confusing and non-standardized.

A few weeks ago, some Automatticians and I went to the 7th CloudFest Hackathon in Rust, Germany to explore a solution for this. We started hacking on a deeply nerdy project, JSON Schema forms and fields, and ended up with a fascinating approach to an age-old question: What if you could register custom post types and custom fields directly in the WordPress admin?

Forty-eight hours turns an idea into reality

The CloudFest Hackathon is an event that allows developers from around the globe to take ideas and turn them into realities.

During the Hackathon, teams of developers from various content management systems and hosting companies come together to contribute to projects that align with the core principles of the event: the projects must be not-for-profit, interoperable, and open source.

Last year, we worked on a project that allowed us to embed WordPress directly in VS Code. We built the WordPress Playground VS Code extension on top of WordPress Playground. It uses WebAssembly to run WordPress entirely within the browser, and it turned out pretty darn slick. 

This year, we focused on a JSON Schema Field/Form Renderer. While most of us explored using JSON Schema to dynamically register admin forms and fields, Dennis Snell and Adam ZieliÅ„ski decided to take the project one step further! They hacked together a plugin that introduced the ability to register custom post types and custom fields directly from the WordPress admin. More notably, everything happens within the block editor—you have to see it to believe it:

This work poses some interesting possibilities for custom post type and custom field implementation because it could fundamentally change the way low- to no-code WordPress users modify their sites.

Naturally, I took the idea to Twitter/X:

Should WordPress let you register custom post types and custom fields from the admin? #CFHack2024

— daniel (@dbchhbr) March 17, 2024

I got quite a range of responses, ranging from "Heck Yes! It should have already been a core feature now. Such an integral part of every other site" to "Admin should only be for content and user management. Everything else should be configured in code and version controllable."

So why the range in responses? Let's discuss.

It turned out to be pretty simple

Dennis and Adam built our prototype using the following conventions:

  • A custom post type wp_data_type holds templates for user-defined data types.
  • The title of a post in the wp_data_type defines the name of the new data type. The post itself is the rendering template and comprises any set of normal blocks. Names are given to select block attributes within the post, and these names are mapped into the data type.
  • When creating new posts for the given data type, the locked template is copied from the wp_data_type template, and the block attribute annotations are preserved.
  • Finally, when rendering the wp_data_type template, the attributes are pulled from the individual post of the given data type and spliced into the template.

The fascinating idea is that we don't have to think about form fields; blocks already provide a rendering view and a modal editing experience. We can rely on the fundamental way blocks work and use the very same user experience to create custom data types in a way that users are already familiar with when editing a post or a site.

An orange arrow pointing to the Content field in the block settings for a custom post type.
We can provide JSON-LD markup properties to the block editor using our Custom Fields Names block settings.

Custom post types define custom data types, so we use a template to not only define the data type, but also to provide a default rendering template. Each data attribute within a post type has a field where it's possible to define that field with its JSON-LD property. 

For example, say you had a "Book" custom post type. A few JSON-LD properties you could define using custom fields are:

  • description
  • copyrightYear
  • author
  • bookEdition
  • bookFormat
  • isbn
  • numberOfPages

We also chose to store a copy of each block attribute in the JSON attributes for that block. Since WordPress can now provide a post-to-JSON function, which merges the extracted attributes with the names assigned in the custom post type template, that template may have changed since the custom post was created. This means that no database migrations are necessary to render an updated version of a post.

Store Copy of Each Block Attribute in the JSON Attributes for the Block

The best part? The WordPress infrastructure that already exists (aka Gutenberg!) defines the data type. Because these custom posts are normal posts, and because they adopt the locked template for the data type definition, they are, in fact, renderable on their own! Even if the template has been updated and only the post itself is rendered, it will still display a meaningful representation of the data type as it was when it was created.

While our original Hackathon project was tailored towards developers and UX designers who would love to see a forms and fields API in WordPress, this prototype puts more power in the hands of low- to no-code WordPress users.

It also opens up a world of possibilities for providing a rendering view for any structured data. Imagine uploading a CSV and mapping the column names to block attributes, or connecting to a database or JSON API to map the records in the same way. 

For example, if you had a CSV with business names, addresses, a rating, and a description, we could take that template post and insert a map block, a heading block, a star rating block, and a paragraph block and set the attributes to map to the CSV columns. It's essentially an instant structured data renderer!

But even if we can define custom post types and fields in the editor, should we, as a WordPress community, consider adding it to core?

The existential question: Should it exist?

Adding this kind of functionality into WordPress core could open up a ton of opportunities for the average WordPress user. Instead of needing to get a developer involved to add a custom post type to their site, a user could simply do it themselves and define the necessary fields and structured data attributes. 

On the other hand, allowing everyday users, who may not have a full grasp of how custom post types and structured data should work, free reign to create these data types themselves could have detrimental effects on the user experience of their websites. Clunky or incorrect implementation of structured data markup could also cause issues with how search engines crawl these sites, causing unintended negative impacts to search traffic.

Not only that, but as of right now, if a custom post type is accidentally deleted, all of the content posted to that custom post type will no longer be accessible through the admin (even though it will still be stored in the database). The user could think they "lost" their data.

Let's talk about it

What do you think? Are you in favor of giving website owners the ability to change and customize their custom post types and attributes? Or are there some website features that should always require a more technical hand and implementer? 

We'd love to chat with you about your thoughts in the comments below.

For another interesting exploration on a related idea, check out this discussion on GitHub with the core team.


Thanks to Lars Gersmann for leading the JSON Schema project with me and to everyone on the Syntax Errors team: Adam Zieliński, Dennis Snell, Julian Haupt, Michael Schmitz, Anja Lang, Thomas Rose, Marko Feldmann, Fabian Genes, Michael Schmitz, Jan Vogt, Lucisu, Maximilian Andre, Marcel Schmitz, and Milana Cap.

Comment
You can also reply to this email to leave a comment.

WordPress.com News © 2024. Manage your email settings or unsubscribe.

WordPress.com and Jetpack Logos

Get the Jetpack app

Subscribe, bookmark, and get real-time notifications - all from one app!

Download Jetpack on Google Play Download Jetpack from the App Store
WordPress.com Logo and Wordmark title=

Automattic, Inc. - 60 29th St. #343, San Francisco, CA 94110  

Read more

Subscribe via email

Share This:
Facebook Twitter Google+ Pinterest Linkedin
Author Image

About Media Mamat Turbo
Templatesyard is a blogger resources site is a provider of high quality blogger template with premium looking layout and robust design. The main mission of templatesyard is to provide the best quality blogger templates.

By Media Mamat Turbo at April 15, 2024
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Popular

  • This Weeks New Digital Building Blog Post
    MAMAT, check out this weeks new Digital Building Blog. ...
  • 8 Must-Try AI Tools for Web Development (Build Faster & Smarter)
    8 Must-Try AI Tools for Web Development (Build Faster & Smarter)
    Artificial intelligence excels at automating repetitive tasks and streamlining t...
  • [New post] Level Up Your Author HQ With GoCreate.Me
    David Gaughran posted: " Author websites are an increasingly important tool, but one that can cause a lot of aggravation. W...
  • When Typepad Shut Down, We Helped 3,684 Blogs Find a New Home
    30 days' notice. Years of memories at stake. Here's how WordPress.com st...
  • Covid Turbulence – how countries got cancellations under control
    ...

Sponsor

Powered by Blogger.

Blog Archive

  • January 2026 (7)
  • December 2025 (16)
  • November 2025 (19)
  • October 2025 (11)
  • September 2025 (16)
  • August 2025 (22)
  • July 2025 (19)
  • June 2025 (13)
  • May 2025 (21)
  • April 2025 (32)
  • March 2025 (32)
  • February 2025 (20)
  • January 2025 (44)
  • December 2024 (15)
  • November 2024 (17)
  • October 2024 (14)
  • September 2024 (18)
  • August 2024 (19)
  • July 2024 (14)
  • June 2024 (21)
  • May 2024 (17)
  • April 2024 (24)
  • March 2024 (29)
  • February 2024 (24)
  • January 2024 (63)
  • December 2023 (32)
  • November 2023 (29)
  • October 2023 (25)
  • September 2023 (33)
  • August 2023 (21)
  • July 2023 (21)
  • June 2023 (29)
  • May 2023 (19)
  • April 2023 (14)
  • March 2023 (16)
  • February 2023 (18)
  • January 2023 (16)
  • December 2022 (20)
  • November 2022 (24)
  • October 2022 (22)
  • September 2022 (19)
  • August 2022 (24)
  • July 2022 (31)
  • June 2022 (34)
  • May 2022 (31)
  • April 2022 (37)
  • March 2022 (28)
  • February 2022 (31)
  • January 2022 (39)
  • December 2021 (35)
  • November 2021 (37)
  • October 2021 (32)
  • September 2021 (18)
  • August 2021 (48)
  • July 2021 (43)
  • June 2021 (44)
  • May 2021 (65)
  • April 2021 (72)
  • March 2021 (64)
  • February 2021 (50)
  • January 2021 (47)
  • December 2020 (47)
  • November 2020 (43)
  • October 2020 (96)
  • September 2020 (100)
  • August 2020 (128)
  • July 2020 (87)
  • June 2020 (108)
  • May 2020 (107)
  • April 2020 (90)
  • March 2020 (91)
  • February 2020 (77)
  • January 2020 (88)
  • December 2019 (105)
  • November 2019 (107)
  • October 2019 (102)
  • September 2019 (98)
  • August 2019 (118)
  • July 2019 (115)
  • June 2019 (99)
  • May 2019 (115)
  • April 2019 (103)
  • March 2019 (112)
  • February 2019 (118)
  • January 2019 (109)
  • December 2018 (106)
  • November 2018 (128)
  • October 2018 (97)
  • September 2018 (126)
  • August 2018 (59)
  • January 2013 (1)

Search This Blog

Popular Posts

  • This Weeks New Digital Building Blog Post
    This Weeks New Digital Building Blog Post
    MAMAT, check out this weeks new Digital Building Blog. ...
  • 8 Must-Try AI Tools for Web Development (Build Faster & Smarter)
    8 Must-Try AI Tools for Web Development (Build Faster & Smarter)
    Artificial intelligence excels at automating repetitive tasks and streamlining t...
  • [New post] Level Up Your Author HQ With GoCreate.Me
    [New post] Level Up Your Author HQ With GoCreate.Me
    David Gaughran posted: " Author websites are an increasingly important tool, but one that can cause a lot of aggravation. W...
  • When Typepad Shut Down, We Helped 3,684 Blogs Find a New Home
    When Typepad Shut Down, We Helped 3,684 Blogs Find a New Home
    30 days' notice. Years of memories at stake. Here's how WordPress.com st...
Crafted with by TemplatesYard