PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Limit number of published posts per form per user

  1. I have came to Gravity Forms from TDO Mini Forms where I could use throttling options to set a limit of active posts per user over any period of time I wanted. I ideally need to be able to do the same, however I do not need to do it over a period of time. Whenever a user uses a form, the post is always set to their account so that the user is the author of the post they submitted.

    For example. All users will be registered before they can access the form (I already have this set by protecting access to the form with a membership plugin).

    There are two forms that need to limit the number of active (published) posts per user. One form needs to be limited to 1 and the other needs to be limited to 5. How can I check the number of active (published) posts that a user has, or how can I restrict usage of a form based on how many active (published) posts a user already has?

    Posted 12 years ago on Monday January 16, 2012 | Permalink
  2. Hi BusinessOnline,

    This is going to require some custom code. Here is a high level breakdown of how this could be accomplished.

    1. use gform_pre_render hook to add this customization
    2. get the current user data like so:
      [php]
      $current_user = wp_get_current_user();
    3. in custom function, use WP's get_posts() to retrieve a list of posts the current user has authored
    4. check the count() of the returned posts, if greater than your max, output a style block with a style like:
      [css]
      #gform_wrapper_1 { display: none; }
    5. this will hide the form so most users won't look any deeper. For clever users, you'll need to add similar functionality to the gform_validation hook as well to prevent the hidden from from being submitted.
    Posted 12 years ago on Monday January 16, 2012 | Permalink