programing

사용자 지정 분류법이 Post Gutenberg 편집기에 표시되지 않음

codeshow 2023. 3. 8. 21:39
반응형

사용자 지정 분류법이 Post Gutenberg 편집기에 표시되지 않음

Wordpress에 커스텀 분류법을 등록했는데, Gutenberg가 도입되어 있기 때문에 표준 Wordpress 투고에 표시되지 않는 이유를 알 수 없습니다.즉, 투고를 추가하거나 편집할 때 문서 사이드바에 표시되지 않습니다.분명히 표준 분류법인 '카테고리'와 '태그'도 마찬가지다.

'show_in_rest' => true가 존재함을 확인했습니다.분류법 등록에 해당하지만 별 차이가 없습니다.

왼쪽 메인 메뉴의 「Posts」아래에 표시되므로, 부분적으로 등록하고 있는 것 같습니다만, 구텐베르크와 관련된 것이 아닐까요?

좋은 생각 있어요?

// Register taxonomy
add_action( 'init', 'register_taxonomy_articles_element' );

function register_taxonomy_articles_element() {

    $labels = array( 
        'name' => _x( 'Elements', 'articles_element' ),
        'singular_name' => _x( 'Element', 'articles_element' ),
        'search_items' => _x( 'Search Elements', 'articles_element' ),
        'popular_items' => _x( 'Popular Elements', 'articles_element' ),
        'all_items' => _x( 'All Elements', 'articles_element' ),
        'parent_item' => _x( 'Parent Element', 'articles_element' ),
        'parent_item_colon' => _x( 'Parent Element:', 'articles_element' ),
        'edit_item' => _x( 'Edit Element', 'articles_element' ),
        'update_item' => _x( 'Update Element', 'articles_element' ),
        'add_new_item' => _x( 'Add New Element', 'articles_element' ),
        'not_found' => _x( 'No Elements found', 'articles_element' ),
        'new_item_element' => _x( 'New Element', 'articles_element' ),
        'separate_items_with_commas' => _x( 'Separate Elements with commas', 'articles_element' ),
        'add_or_remove_items' => _x( 'Add or remove elements', 'articles_element' ),
        'choose_from_most_used' => _x( 'Choose from the most used elements', 'articles_element' ),
        'menu_name' => _x( 'Elements', 'articles_element' )
    );

    $args = array( 
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_in_nav_menus' => true,
        'show_in_rest' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'hierarchical' => true,
        'rewrite' => true,
        'query_var' => true
    );

    register_taxonomy( 'element', array('post'), $args );
}

분류법 또는 구텐베르크 에디터를 표시하는 데 문제가 있는 경우'show_in_rest' => true,커스텀 투고 타입과 분류법 인수에 모두 사용됩니다.

Gutenberg는 REST API를 기반으로 작업하기 때문에 커스텀 포스트 타입과 분류법에 대해 REST API 지원을 켜야 합니다.키를 추가해야 합니다.show_in_rest = true고객님께$args어레이 전체 코드는 다음과 같습니다.

$args = array( 
    'labels' => $labels,
    'public' => true,
    'show_in_rest' => true, // add support for Gutenberg editor
    'publicly_queryable' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => true,
    'show_ui' => true,
    'show_tagcloud' => true,
    'hierarchical' => true,
    'rewrite' => true,
    'query_var' => true
);

조사 결과, 상기 코드(정답)가 문제가 아닌 것 같습니다.이 문제는 'type'이라는 이름의 두 번째 사용자 지정 분류 체계에서 발생했습니다.알고 보니 워드프레스는 '예약어'를 다수 포함하고 있는데, 그 중 하나가 '유형'이다.이 분류법이 이름이 바뀌면 구텐베르크를 포함한 두 분류법 모두 올바르게 작동합니다.

당면한 문제는 다음 사항을 변경함으로써 해결할 수 있습니다.'rewrite'리스트 내의 속성true안으로array( 'slug' => 'your-taxonomy-slug' )그래서 새로운'rewrite'처럼 보여야 한다'rewrite' => array( 'slug' => 'your-taxonomy-slug' )슬러그 대신 어떤 슬러그라도 넣어도 되고your-taxonomy-slug.

왜 이것이 작동해야 하는지는 잘 모르겠습니다만, 블록 에디터는 Rest API를 사용하고 있는 것 같습니다만, 어떤 이유로 slug를 고쳐 쓰지 않으면 분류법을 처리할 수 없습니다.다른 모든 기능은 정상적으로 동작하고 있기 때문에 이상합니다.

이 방법이 작동하지 않으면 테마 또는 플러그인이 충돌할 수 있습니다.컨플릭트의 원인이 무엇인지 확인하기 위해 비활성화 작업을 시도합니다.

언급URL : https://stackoverflow.com/questions/55870989/custom-taxonomy-not-showing-in-post-gutenberg-editor

반응형