Категория пользовательского типа сообщения - PullRequest
1 голос
/ 02 мая 2020

Я создал пользовательский тип поста для портфолио, как бы я ни создавал таксономию, то есть категории портфеля, но дело в том, когда я создал любой пост и назначил ему категорию, поэтому после публикации пост виден, но категория не видно в сообщении, я не знаю, почему оно скрывается после публикации сообщения. Спасибо

Это мой код

/**
 * custom post Portfolio_page.
 */

function custom_post_type() {
    $labels = array(
        'name'                => __( 'portfolio' ),
        'singular_name'       => __( 'portfolio'),
        'menu_name'           => __( 'portfolios'),
        'parent_item_colon'   => __( 'Parent Deal'),
        'all_items'           => __( 'All portfolios'),
        'view_item'           => __( 'View portfolio'),
        'add_new_item'        => __( 'Add New portfolio'),
        'add_new'             => __( 'Add New'),
        'edit_item'           => __( 'Edit portfolio'),
        'update_item'         => __( 'Update portfolio'),
        'search_items'        => __( 'Search portfolio'),
        'not_found'           => __( 'Not Found'),
        'not_found_in_trash'  => __( 'Not found in Trash')
    );
    $args = array(
        'label'               => __( 'portfolio'),
        'description'         => __( 'Loops digital portfolio'),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
        'public'              => true,
        'hierarchical'        => false,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'has_archive'         => true,
        'can_export'          => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page'
);
    register_post_type( 'portfolio', $args );
}
add_action( 'init', 'custom_post_type', 0 );


/**
 * Custom Taxonomy for Custom post type
 */


add_action( 'init', 'custom_post_type_taxonomy', 0 );

function custom_post_type_taxonomy() {

 $labels = array(
   'name' => _x( 'portfolio_categories', 'taxonomy general name' ),
   'singular_name' => _x( 'portfolio_category', 'taxonomy singular name' ),
   'search_items' =>  __( 'Search portfolio_categories' ),
   'all_items' => __( 'All portfolio_categories' ),
   'parent_item' => __( 'Parent portfolio_categories' ),
   'parent_item_colon' => __( 'Parent portfolio_categories:' ),
   'edit_item' => __( 'Edit portfolio_categories' ), 
   'update_item' => __( 'Update portfolio_categories' ),
   'add_new_item' => __( 'Add New portfolio_categories' ),
   'new_item_name' => __( 'New portfolio_categories Name' ),
   'menu_name' => __( 'portfolio_categories' ),
 );     

 register_taxonomy('portfolio_categories',array('portfolio'), array(
   'hierarchical' => true,
   'labels' => $labels,
   'show_ui' => true,
   'show_admin_column' => true,
   'query_var' => true,
   'rewrite' => array( 'slug' => 'portfolio_categories' ),
 ));
}

1 Ответ

0 голосов
/ 06 мая 2020
please try this function



   function portfolio_post_type() {

        $labels = array(
        'name'               => __( 'portfolio'),
        'singular_name'      => __( 'portfolio' ),
        'add_new'            => __( 'add portfolio'),
        'add_new_item'       => __( 'add portfolio' ),
        'edit_item'          => __( 'edit' ),
        'new_item'           => __( 'new portfolio' ),
        'all_items'          => __( ' all ' ),
        'view_item'          => __( 'view ' ),
        'search_items'       => __( 'searcj ' ),
        'not_found'          => __( 'nothing found' ),
        'not_found_in_trash' => __( 'nothing found' ),
        'parent_item_colon'  => '',
        'menu_name'          => 'portfolio'
        );
      $args = array(
        'label'                 => __( 'portfolio' ),
        'description'           => __( 'portfolio' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields' ),
        'taxonomies'            => array( 'portfolio_portfolio' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'show_in_rest'          => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'post',
      );
      register_post_type( 'portfolio', $args );
     }
    add_action( 'init', 'portfolio_post_type', 0 );
    // Register Custom Taxonomy
    function portfolio_portfolio_taxonomy() {

      $labels = array(
        'name'                       => __( 'portfolio', 'Taxonomy General Name' ),
        'singular_name'              => __( 'portfolio', 'Taxonomy Singular Name' ),
        'menu_name'                  => __( 'portfolio' ),
        'all_items'                  => __( 'all' ),
        'parent_item'                => __( 'Parent Item' ),
        'parent_item_colon'          => __( 'Parent Item:' ),
        'new_item_name'              => __( 'new' ),
        'add_new_item'               => __( 'new' ),
        'edit_item'                  => __( 'edit' ),
        'update_item'                => __( 'update' ),
        'view_item'                  => __( 'view' ),
        'separate_items_with_commas' => __( 'Separate items with commas' ),
        'add_or_remove_items'        => __( 'Add or remove items' ),
        'choose_from_most_used'      => __( 'Choose from the most used' ),
        'popular_items'              => __( 'Popular Items' ),
        'search_items'               => __( 'Search Items' ),
        'not_found'                  => __( 'Not Found' ),
        'no_terms'                   => __( 'No items' ),
        'items_list'                 => __( 'Items list' ),
        'items_list_navigation'      => __( 'Items list navigation' ),
      );
      $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
        'show_in_rest'               => true
      );
      register_taxonomy( 'portfolio_portfolio', array( 'portfolio' ), $args );

    }
    add_action( 'init', 'portfolio_portfolio_taxonomy', 0 );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...