【问题标题】:Limit a User to Only Create One Custom Post Type Post限制用户仅创建一个自定义帖子类型帖子
【发布时间】:2019-04-04 16:30:07
【问题描述】:

我有一个服务提供商的自定义帖子类型。这本质上是他们的简历页面。我设置他们只能编辑他们自己的简历页面,但是要做到这一点,我必须授予他们创建自己的简历页面的能力(添加新的)。有没有办法在他们创建自己的页面后删除“添加新”功能?

【问题讨论】:

    标签: wordpress custom-post-type capability


    【解决方案1】:

    我想知道这个插件是否对你有帮助:

    http://wordpress.org/plugins/bainternet-posts-creation-limits/

    此插件可帮助您限制帖子/页面/自定义帖子的数量 每个用户可以在您的网站上创建的类型。

    【讨论】:

    • 我刚刚完成了那个插件的安装,它就像一个魅力。谢谢!
    【解决方案2】:

    我使用上面的插件,效果很好。另一种“粗略”的方法是使用一个前端发布插件,并使用下面的条件代码来限制作者,如果他们已经发布了自定义帖子...

    为前端发布表单所在的特定页面制作一个页面模板,并在适当的地方添加它...

    <?php if (( 0 == count_user_posts( get_current_user_id(), "CUSTOM-POST-TYPE" ) && is_user_logged_in() && current_user_can('USER-ROLE-CAPABILITY') && !current_user_can( 'manage_options' ))) { ?>
        <?php the_content(); ?>
    <?php } ?>
    

    您还需要阻止他们访问后端。

    【讨论】:

      【解决方案3】:
      function post_published_limit() {
          $max_posts = 3; // change this or set it as an option that you can retrieve.
          $author = $post->post_author; // Post author ID.
      
          $count = count_user_posts( $author, 'CUSTOMPOSTTYPE'); // get author post count
      
          if ( $count > $max_posts ) {
              // count too high, let's set it to draft.
      
              $post = array('post_status' => 'draft');
              wp_update_post( $post );
          }
      }
      add_action( 'publish_CUSTOMPOSTTYPE', 'post_published_limit' );
      

      希望这是你的答案。如果这是您的答案,请接受。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-19
        • 1970-01-01
        • 2020-06-06
        • 1970-01-01
        • 2016-05-13
        • 2018-06-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多