Reputation: 41
so I have this custom post type made in my functions.php in Wordpress I have my field group from Advanced custom fields linked to it
what I have for code for the Custom post type is
function init_members() {
$labels = array(
'name' => 'Leden',
'singular_name' => 'Lid',
'menu_name' => 'Leden',
'name_admin_bar' => 'Lid',
'add_new' => 'Nieuw lid',
'add_new_item' => 'Nieuw lid',
'new_item' => 'Nieuw lid',
'edit_item' => 'Bewerk lid',
'all_items' => 'Alle leden',
'search_items' => 'zoek leden',
'not_found' => 'Geen leden gevonden',
'not_found_in_trash' => 'Geen leden gevonden in de prullenbak'
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => true,
'rewrite' => array('slug' => 'lid'),
'has_archive' => false,
'supports' => array(''),
'show_in_rest' => true,
'menu_icon' => 'dashicons-groups'
);
register_post_type('members', $args);
}
add_action('init', 'init_members');
and this code is for what u see in the picture below
function add_member_columns ( $columns ) {
unset($columns['date']);
return array_merge ( $columns, array (
'contactperson' => __ ( 'Contactpersoon' ),
'phone_number' => __ ( 'Telefoonnummer' ),
'email' => __ ( 'Email' ),
) );
}
add_filter ('manage_members_posts_columns', 'add_member_columns' );
function fill_member_columns ( $column, $post_id ) {
switch ( $column ) {
case 'contactperson':
echo get_post_meta ( $post_id, 'contactperson', true );
break;
case 'phone_number':
echo get_post_meta ( $post_id, 'phone_number', true );
break;
case 'email':
echo get_post_meta ( $post_id, 'email', true );
break;
}
}
add_action ('manage_members_posts_custom_column', 'fill_member_columns', 10, 2 );
so this is what it looks like in the custom post type page
In the advanced custom fields the first field is called company. how do i get it to be the title because it now just pics automatic concept as title?
Upvotes: 0
Views: 395
Reputation: 688
In your array $args (in the code for making the custom post type) you see this line:
'supports' => array('')
In this array you can add all things to support. You can add title to it to make the titlefield appear, like this:
'supports' => array('title')
You can add multiple things to ' support' here, like editor and thumbnail. You can find a complete list and explanation about it in the wordpress developer manual on registering post types
If you want to show an ACF field later in your template, you can add it the same way you did with contactpersoon, telefoonnummer etc.
Upvotes: 2