ACF for custom post type archive pages: which hook to use?

I’m trying to register ACF options pages for each custom post type defined in the theme:

$post_types = get_post_types(
array(
‘public’ => true,
‘_builtin’ => false
),
‘objects’
);

foreach ($post_types as $post_type) {
$post_type_slug = $post_type->slug;
$options_title = $post_type->name . “: Archive Options”;
acf_add_options_page(array(
‘page_title’ => $options_title,
‘menu_title’ => $options_title,
‘parent_slug’ => “edit.php?post_type={$post_type_slug}”,
‘menu_slug’ => “{$post_type_slug}-archive-options”,
‘capability’ => ‘edit_posts’,
‘redirect’ => false
));
}

This is called on the acf/init hook (as recommended by the docs), while the custom post types are registered on WordPress init hook. (I should also probably mention that both actions are hooked as part of an after_setup_theme action.)

However, get_post_types() returns an empty array. Is this a sequence mismatch between the hooks? (i.e. posts are registered only after the acf/init hook)

Read more here:: ACF for custom post type archive pages: which hook to use?

Leave a Reply

Your email address will not be published. Required fields are marked *