简体   繁体   English

标题自定义帖子类型 ACF

[英]Title custom post type ACF

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所以我在 Wordpress 的functions.php 中创建了这个自定义帖子类型 我将高级自定义字段中的字段组链接到它

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?我如何让它成为标题,因为它现在只是将自动概念图片作为标题?

In your array $args (in the code for making the custom post type) you see this line:在您的数组 $args(在用于制作自定义帖子类型的代码中)中,您会看到这一行:

'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您可以在注册帖子类型wordpress 开发人员手册中找到有关它的完整列表和说明

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.如果您想稍后在模板中显示 ACF 字段,您可以像添加联系人、电话号码等一样添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM