Support

Account

Home Forums ACF PRO How to replace custom post type slug by an ACF value? Reply To: How to replace custom post type slug by an ACF value?

  • It would depend on the order that things happen. Usually you add custom post types on the init hook. ACF also initializes on the init hook. To use get_field() ACF needs to be initialized before you try to get the value. You may also run into an issue if you try to get a field before ACF fires the acf/include_fields hook.

    In this case, assuming that this is on an options page, I would use the built in WP function get_option() to get the ACF field value. Usually on an options page the option name will be “options_YOUR-FIELD-NAME”. Doing this you don’t need to worry about ACF when you register your post type.