sourcetip

두 개의 사용자 지정 게시물 유형 동일한 범주

fileupload 2023. 10. 15. 17:34
반응형

두 개의 사용자 지정 게시물 유형 동일한 범주

여러 커스텀 포스트 타입에 대해 동일한 카테고리를 추가할 수 있습니까?

예를들면,

쿠폰 포스트 타입 - 딜 포스트 타입 - 둘 다 건강, 여행 등과 같은 공통 카테고리를 공유해야 합니다.

그러나 새로운 포스트 유형을 만들 때는 사용자 정의 카테고리도 제공해야 합니다.

사용자 지정 카테고리가 없는 사용자 지정 게시물 유형을 만드는 방법을 알고 계십니까?

예, custom-post-type에는 여러 분류(카테고리, 태그, custom)가 있을 수 있습니다.

예, 분류 체계 없이 사용자 지정 게시물 유형을 가질 수 있습니다.

사용자 지정 게시 유형에 범주를 추가하는 작업은 다음과 같습니다.

'taxonomies'          => [ 'category' ], // <--- add this (or use 'post_tag' to add tags to the CPT)
'public'              => true,
'show_ui'             => true,
'exclude_from_search' => true,
'hierarchical'        => true,
'supports'            => [
    'title', 
    'editor', 
    'thumbnail',
],
'query_var'           => true,

여러 포스트 유형에 사용자 정의 분류법을 추가하려면 다음 작업을 수행할 수 있습니다.

function people_init() {
    // create a new taxonomy
    register_taxonomy(
        'people', [ // <-- 'people' taxo added to posts, pages, & custom_post_type
            'post', 
            'page', 
            'custom_post_type',
        ],
        array(
            'label'        => __( 'People' ),
            'rewrite'      => [
                'slug'     => 'person',
            ],
            'capabilities' => [
                'assign_terms' => 'edit_guides',
                'edit_terms'   => 'publish_guides',
            ]
        )
    );
}
add_action( 'init', 'people_init' );

언급URL : https://stackoverflow.com/questions/36344919/two-custom-post-type-sharing-same-category

반응형