Поддержка Проблемы и решения Отображение категорий для custom post types.

  • Решено AlphaCentavr

    (@alphacentavr)


    Здравствуйте.
    Возникла такая проблема. Есть custom post type peoples. Для него я хочу сделать таксономию — Допустим Writer. Ну у таксономии для моего типа поста есть категории, скажем novelist, poet, storyteller. Далее я хочу отобразить категорию novelist и отобразить все peoples, принадлежащих к категории novelist. К слову посты типа Peoples в моем случае прекрасно отображаются. А вот категории постов — Not Found.
    Вот код:
    1. Создание custom post type:

    add_action( 'init', 'create_post_type' );
    
    function create_post_type() {
        register_post_type( 'peoples',
            array(
                'labels' => array(
                    'name' => __( 'Peoples' ),
                    'singular_name' => __( 'People' )
                ),
                'public' => true,
                'has_archive' => true,
                'supports' => array('title', 'editor', 'custom-fields', 'thumbnail'),
                'rewrite' => array('slug' => 'people')
            )
        );
    }

    2. Создание таксономии для вышесозданного типа поста:

    add_action( 'init', 'create_writer_taxonomies', 0 );
    
    function create_writer_taxonomies(){
      $labels = array(
        'name' => _x( 'Writers', 'taxonomy general name' ),
        'singular_name' => _x( 'Writer', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Writers' ),
        'all_items' => __( 'All Writers' ),
        'parent_item' => __( 'Parent Writer' ),
        'parent_item_colon' => __( 'Parent Writer:' ),
        'edit_item' => __( 'Edit Writer' ),
        'update_item' => __( 'Update Writer' ),
        'add_new_item' => __( 'Add New Writer' ),
        'new_item_name' => __( 'New Genre Name' ),
        'menu_name' => __( 'Writer' ),
      );
    
      register_taxonomy('writer', array('peoples'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'writer' ),
      ));
    }

    Так, например, хочу просмотреть всех people из категории horror, т е перехожу по урл (в админке есть ссылка для перехода) — http://volpelaw.dev/writer/poet/
    и Not Found. Хотя еще раз скажу, сами post typ-ы прекрасно отображаются.
    Спасибо за любую помощь.

  • Тема «Отображение категорий для custom post types.» закрыта для новых ответов.