I’ve established a custom post type named “Dealers,”. Among them, there’s a distinct dealer with unique fields and a dedicated page. Although it falls under the category of dealers, I prefer to manage this dealer’s page within the section of the custom post type.
That’s why I’ve created a submenu page within this custom post type. Here, I want to add the appropriate ACF fields.
Below is how I created my custom post type:
<?php
/**
* Custom posttype
*/
function vivafloors_custom_posttype_dealer()
{
$dealersSlug = 'dealers';
if (is_array(get_field('dealers', 'option'))) {
$dealersSlug = get_field('dealers', 'option')['dealers_slug'];
}
$dealersName = ucfirst($dealersSlug);
$labels = array(
'name' => _x($dealersName, 'Post Type General Name', 'vivafloors'),
'singular_name' => _x('Dealer', 'Post Type Singular Name', 'vivafloors'),
'menu_name' => __('Dealers', 'vivafloors'),
'name_admin_bar' => __('Dealer', 'vivafloors'),
// 'parent_item_colon' => __('Hoofd case:', 'vivafloors'),
'all_items' => __('Alle dealers', 'vivafloors'),
'add_new_item' => __('Nieuwe dealer', 'vivafloors'),
'add_new' => __('Nieuwe dealer', 'vivafloors'),
'new_item' => __('Nieuwe dealer', 'vivafloors'),
'edit_item' => __('Dealer bewerken', 'vivafloors'),
'update_item' => __('Wijzig dealer', 'vivafloors'),
'view_item' => __('Bekijk dealer', 'vivafloors'),
'search_items' => __('Zoek dealer', 'vivafloors'),
'not_found' => __('Not found', 'vivafloors'),
'not_found_in_trash' => __('Not found in Trash', 'vivafloors'),
);
$rewrite = array(
'slug' => $dealersSlug,
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __('dealer', 'vivafloors'),
'description' => __('Dealers', 'vivafloors'),
'labels' => $labels,
'supports' => array('title', 'revisions', 'thumbnail', 'revisions'),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-store',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite
);
register_post_type('dealer', $args);
register_taxonomy('dealer_category','dealer', array('hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true));
}
// Hook into the 'init' action
add_action('init', 'vivafloors_custom_posttype_dealer', 0);
And this is how I create a submenu page within this custom post type:
function add_custom_page_to_menu() {
add_submenu_page(
'edit.php?post_type=dealer',
__('Dealer Vivafloors', 'text_domain'),
__('Dealer Vivafloors', 'text_domain'),
'edit_posts',
'dealer-vivafloors',
'call_back_function'
);
}
add_action('admin_menu', 'add_custom_page_to_menu');
function call_back_function() {
?>
<h1>Hello</h1>
<?php
}
I’m encountering difficulty in showcasing ACF fields on the submenu page. Is the recommended approach to manage this through ACF fields? I’ve been unable to find a method to connect this submenu page with ACF fields. Or do I need to trigger something within the call_back_function?
Any ideas?