WordPress - How To Dynamically Populate A Post Type In An ACF Field

06 September 2021
3 min read

Advanced Custom Field (ACF) is a great plugin that helps ease the gap between PHP coding in WordPress — from the WP-admin fields and the saving to database. At Oangle, we use the Pro version of ACF plugin for 90% of our projects to build our admin panel. In order to ease the technical difficulties for our clients and users in managing the website and content, we build an architecture of ACF fields which enables and empowers the web administrator to easily use the field options to change content or options. There is also a free version of it that is a great tool for any aspiring WordPress developer, you can find more about here.

When we build pages, we create an ACF field for every element so that the content can easily be changed by the administrator. Imagine having a homepage, where there might be a section called ‘featured blog articles’.

<insert image eg of this 3 part layout>

blog gist example

There are many ways we can build this in our PHP code. The most common example is to always list the latest three articles. For some clients, however, they want to always be able to choose the three to be shown. In this case, the old way of doing this would be more manual — use a repeater to allow the admin to add a title, a URL to the blog article, an image, a checkbox to enable/disable the item, etc. This will enable admins to change the ‘featured’ blog articles displayed on the homepage at will. However, this is quite a manual process.

Using the following piece of code, we can easily populate content in the ACF field:

Remember to change the name of your field in the above code.

Unsure of where to insert this? Don’t want to break anything? Our team of WordPress developers in Singapore can accomplish this job for you safely and efficiently. We are highly experienced in WordPress and web development and are equipped in solving any issues you might be facing.

Be the first to get tips on web design, WordPress & more

Sign up for our newsletter to be in the loop.



Have queries or need some advice?