如何仅在WordPress中显示自定义帖子

发布于 2025-01-30 14:53:53 字数 605 浏览 1 评论 0原文

我是WordPress的新手,我创建了自定义帖子类型,我希望仅适用于订户(不适合管理员),那么我该怎么做是我当前的代码? 函数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' );

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' );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唠甜嗑 2025-02-06 14:53:53
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' );
} 

书是一种自定义帖子类型,您可以在此处编写自己的代码。
订户无权仪表板。您可以设置编辑规则或其他规则的条件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文