답변:
get_post_types_by_support()
원하는 결과를 얻는 솔루션 인 것으로 나타났습니다 .
$post_types = get_post_types_by_support(array('title', 'editor', 'thumbnail'));
위의 의지 반환 post
, page
및 사용자 정의 포스트 유형이 지원 title
, editor
및 thumbnail
.
이것은 비공개 게시물 유형도 반환하므로 목록을 반복하고 프런트 엔드에서 유형을 볼 수 있는지 확인할 수 있습니다. 이 is_post_type_viewable()
기능 을 사용하여 수행 할 수 있습니다 .
foreach ($post_types as $key => $post_type) {
if (!is_post_type_viewable($post_type)) {
unset($post_types[$post_type]);
}
}
get_post_types()
게시물 유형 객체 의 필드와 일치하는 인수 배열을 허용 합니다 . 따라서 다음과 같이 할 수 있습니다 (테스트되지 않음).
$post_types = get_post_types(array(
'public' => true,
'supports' => array( 'editor', 'title', 'thumbnail' )
), 'objects');
불행히도,이 함수에서 "exclude"와 같은 것을 설정할 수 없으며 정확히을 지원 하는 게시물 유형 만 얻을 수 있습니다 'editor', 'title', 'thumbnail'
.
또는 get_post_types_by_support()
WP 4.5 이상에서만 사용할 수 있습니다 . 또한이 기능을 사용하여 특정 게시물 유형을 제외 할 수는 없지만을 지원하는 특정 경우 editor, title, thumbnail
첨부 파일 게시물 유형은 대부분 제외됩니다 .
$post_types = get_post_types_by_support( array( 'editor', 'title', 'thumbnail' ) );
어떤 경우에도 작동하는 것을 원한다면 더 넓은 기준에 따라 게시물 유형을 얻은 다음 다음과 같이 자신의 배열을 작성하려고합니다.
$_post_types = get_post_types_by_support( array( 'editor', 'title', 'thumbnail' ) );
$post_types = [];
foreach($_post_types as $post_type) {
// In most cases, attachment post type won't be here, but it can be
if( $post_type->name !== 'attachment' ) {
$post_types[] = $post_type;
}
}
supports
이 작동하지 않는 것 같습니까? 지원하는 사용자 정의 게시물 유형이 있는데 editor
사용 supports => array('editor')
하면 빈 결과가 나옵니까? 두 번째 접근법은 효과가있는 것 같습니다.
get_post_types_by_support()
위해 지원을 사용할 수있는 것 같습니다 .