1

I have created a simple plugin to manage my portfolio as a custom post type. everything is OK and works great, but there is no ability to add my custom post type to the menu(also for its taxonomies). note: I have checked as many as ways that I knew before. (show_ui, show_in_nav_menus,...) below is my codes for my CPT

<?php
function oseo_custom_post_type() {
    register_taxonomy( 'portfolio_cat', array('oseo_portfolio'),
        array(
            'show_ui'           => true,
            'hierarchical'      => true,
            'label'             => __('Portfolio Filters', 'oseo-portfolio'),
            'singular_label'    => __('portfolio Filter', 'oseo-portfolio'),
            'rewrite'           => array('slug' =>  'portfolio_type')
        )
    );
    $labels = array(
        'name'                => _x( 'Portfolios', 'Post Type General Name', 'oseo-portfolio' ),
        'singular_name'       => _x( 'Portfolio', 'Post Type Singular Name', 'oseo-portfolio' ),
        'menu_name'           => __( 'Portfolios', 'oseo-portfolio' ),
        'parent_item_colon'   => __( 'Parent Portfolio', 'oseo-portfolio' ),
        'all_items'           => __( 'All Portfolios', 'oseo-portfolio' ),
        'view_item'           => __( 'View Portfolio', 'oseo-portfolio' ),
        'add_new_item'        => __( 'Add New Portfolio', 'oseo-portfolio' ),
        'add_new'             => __( 'Add New', 'oseo-portfolio' ),
        'edit_item'           => __( 'Edit Portfolio', 'oseo-portfolio' ),
        'update_item'         => __( 'Update Portfolio', 'oseo-portfolio' ),
        'search_items'        => __( 'Search Portfolio', 'oseo-portfolio' ),
        'not_found'           => __( 'Not Found', 'oseo-portfolio' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'oseo-portfolio' ),
    );
    $args = array(
        'label'               => __( 'Portfolios', 'oseo-portfolio' ),
        'description'         => __( 'Portfolios', 'oseo-portfolio' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', ),
        'taxonomies'          => array( 'portfolio_cat' ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'rewrite'   =>  array('slug'    =>  'portfolio'),
        'capability_type'     => 'page',
    );
    flush_rewrite_rules();

    register_post_type( 'oseo_portfolio', $args );

}
add_action( 'init', 'oseo_custom_post_type');
?>

one other thing I think may cause this problem is that I use metaboxes for this CPT. I can post those if needed.

  • I found this issue was due to caching on my local browser. – Burgi Jul 17 '18 at 15:46
1
// portfolio code
function codenovo_portfolio_init(){
    $labels = array(
        'name' => _x('Portfolio', 'post type general name'),
        'singular_name' => _x('Portfolio', 'post type singular name'),
        'add_new' => _x('Add New', 'portfolio'),
        'add_new_item' => __('Add New Portfolio'),
        'edit_item' => __('Edit Portfolio'),
        'new_item' => __('New Portfolio'),
        'view_item' => __('View Portfolio'),
        'search_items' => __('Search Portfolio'),
        'not_found' =>  __('No portfolio found'),
        'not_found_in_trash' => __('No portfolio found in Trash'),
        'parent_item_colon' => '',
        'menu_name' => 'Portfolio'
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => false,
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail'),
        'rewrite' => array(
            'slug'       => 'portfolio',
            'with_front' => FALSE,
        )
    );
    register_post_type('portfolio',$args);

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


    register_taxonomy('portfoliocategory',array('portfolio'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'portifolio_category' ),
    ));


}
add_action('init', 'codenovo_portfolio_init');
  • 2
    thank you for your post, you need to explain your answer. – David Lee Mar 6 '17 at 14:22
  • I have just missed some spelling checks – Ali Qorbani Jul 17 '18 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.