简体   繁体   中英

How to display custom post for user only in wordpress

I am new in wordpress, i created custom post type and i want this should display only for subscriber only(not for admin ) So how can i do this Here is my current code? function create_posttype() {

    register_post_type( 'UserProject',
           array(
            'labels' => array(
                'name' => __( 'UserProject' ),
                'singular_name' => __( 'UserProject' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'UserProject'),
            'show_in_rest' => true,
  
        )
    );
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

 if ( current_user_can( 'editor' ) && is_user_logged_in()) { function book_setup_post_type() { $args = array( 'public' => true, 'label' => __( 'Books', 'textdomain' ), 'menu_icon' => 'dashicons-book', ); register_post_type( 'book', $args ); } add_action( 'init', 'book_setup_post_type' ); }

Book is a custom post type you can write your own code here. Subscribers have no rights to the dashboard. You can set the condition for editor rule or another rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM