12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Apr 7, 2020

How to populate Select field’s choices with Custom Post Types in ACF

Sridhar Katakam

This members-only tutorial provides the steps to dynamically set the choices of a Select-type custom field created using Advanced Custom Fields plugin to all the public non-default post types in WordPress.

This will essentially let us set up our own Custom Post Type Selector field.

Note: Depending on your project needs, this may be an overkill and you could simply hardcode the CPT names in your desired order in the Select field. The purpose of this tutorial is not so much the final result but rather how it is done.

This code example can easily be applied to Select, Radio and Checkbox type of fields to populate them from any array.

Step 1

Install and activate ACF (free or Pro).

Create your field group.

Leave the Choices blank.

Step 2

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: Dynamically populate a custom field's choices with CPTs

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right