0

the "authors" in my site should only be allowed to add/edit posts in a single category (i.e.:News). I am preparing the backend for them and I would like to remove the "Posts" menu and show in its place a "News" menu, from which the authors could only list and add/edit the posts in that Category.

No problem to remove the menu items in admin menu, but how can I reach my target to show posts only for the news category?

Thanks

1

The best approach would be to create a custom post type "News" and hide the menu item of "posts" - The code below will create a Custom post type for news

/*
* Creating a function to create our CPT
*/

function custom_post_type() {

// Set UI labels for Custom Post Type
$labels = array(
    'name'                => _x( 'News', 'Post Type General Name', 'texdomain' ),
    'singular_name'       => _x( 'News', 'Post Type Singular Name', 'texdomain' ),
    'menu_name'           => __( 'News', 'texdomain' ),
    'parent_item_colon'   => __( 'Parent News', 'texdomain' ),
    'all_items'           => __( 'All News', 'texdomain' ),
    'view_item'           => __( 'View News', 'texdomain' ),
    'add_new_item'        => __( 'Add New News', 'texdomain' ),
    'add_new'             => __( 'Add New', 'texdomain' ),
    'edit_item'           => __( 'Edit News', 'texdomain' ),
    'update_item'         => __( 'Update News', 'texdomain' ),
    'search_items'        => __( 'Search News', 'texdomain' ),
    'not_found'           => __( 'Not Found', 'texdomain' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'texdomain' 
  ),
);

// Set other options for Custom Post Type

$args = array(
    'label'               => __( 'News', 'texdomain' ),
    'description'         => __( 'News news and reviews', 'texdomain' ),
    'labels'              => $labels,

// Features this CPT supports in Post Editor

    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),

// You can associate this CPT with a taxonomy or custom taxonomy. 

    'taxonomies'          => array( 'genres' ),
    /* A hierarchical CPT is like Pages and can have
    * Parent and child items. A non-hierarchical CPT
    * is like Posts.
    */  
    'hierarchical'        => false,
    '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,
    'capability_type'     => 'page',
   );

 // Registering your Custom Post Type
register_post_type( 'News', $args );

}

/* Hook into the 'init' action so that the function
* Containing our post type registration is not 
* unnecessarily executed. 
*/

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

In order to hide the post menu item from Authors the easy way is using this plugin - https://wordpress.org/plugins/adminimize/ or you can do it with custom functions, more info on this site https://www.wpmayor.com/how-to-remove-menu-items-in-admin-depending-on-user-role/

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.