It doesn’t belong in the database — WordPress + ACF

Photo by WebFactory Ltd on Unsplash

Recently I’ve been working for a client in pair programming (with another developer) and quickly realize there are still questions about how to approach custom fields inside WordPress.

First of all, let’s recap what is ACF — Advanced Custom Fields for WordPress Developers. Advanced Custom Fields is a WordPress plugin which allows you to add extra content fields to your WordPress edit screens. These extra content fields are more commonly referred to as Custom Fields and can allow you to build websites faster and educate your clients quicker.

ACF Inside WP Admin

ACF come with two ways to work with. The first and easy one, it’s to use it out of the box and create group fields inside WordPress admin, bind it to a page (or options, or anything else) then use it inside your code.

Image from https://www.advancedcustomfields.com/

It works really well, but the problem with that is if you lose your database, you’ll not only gonna need to re-create all your content, but also all your website structure.

It probably won’t happen… but there’s more!

The real struggle here is when you work with a team member, if you add fields to affect the database, your pair would have to re-create your fields and configurations to be sure they have what they need.

It would then require a method to sync or use a remote database and it can slow the creating process.

Register Fields Via PHP

The other way is to declare fields programmatically. It means you’ll have to create fields, which gonna be imported into your theme, that will create the fields and attach them to the right part of your theme (page, options, etc.).

To demo you the way to work, let’s add a subtitle field to all pages.

First, let’s create a new file, called acf-page.php under /themes/demo/includes/custom-fields and inside your functions.php just add a loop through inside the includes folder to register all files.

And just like that, if you go inside one of your pages, the subtitle will be appearing!

The cons of this method is that you’d have check documentation more often before you get use to it. But in the end, it will speed up your entire dev process and get you closer to a collaborative approach.

--

--

--

Charming Frontend Developer and entrepreneur who’s got the desire to democratize the web for anyone.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Advanced shortcuts on Android Studio you may not know about.

Using the Google Analytics API in Django / Python

SAML Bearer Grant with WSO2 API Manager & Identity Server

Decision Making statements in C

Wipro’s Boundary Less Container Platform (BLCP)

READ/DOWNLOAD!$ The Practice of Public Relations (12th Edition) FULL BOOK PDF & FULL AUDIOBOOK

Meet the Appchain — Vivi Lin Interviews Kim Zhao Wei, Co-founder of Atocha Protocol

Recap 2018

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jean-Simon Lyonnais

Jean-Simon Lyonnais

Charming Frontend Developer and entrepreneur who’s got the desire to democratize the web for anyone.

More from Medium

A simple PHP framework (6/?) Templating

I created the same Vuetify WebApp 14 times…

How to display an Array in a readable way in PHP

How to display an Array in a readable way in PHP

4 ways to inject dependencies in Symfony that you probably don’t know about?

Symfony Dependency Injection