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 ($37/month or $399 one-time).

Already a member? Log in below or here.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: