Aleš Sýkora / November 28, 2023 / 2 comments

Limit Toolset Form to one submission per user only

Post summary: The easiest way to enable user submit only one post is to hide the form when they already submitted it. So you need to count the number of posts user created and if it is more than 1 then with conditional hide the form. Check the number of posts user created with custom function 3.…

The easiest way to enable user submit only one post is to hide the form when they already submitted it. So you need to count the number of posts user created and if it is more than 1 then with conditional hide the form.

  1. Check the number of posts user created with custom function
/**
 *Count posts of given type, so each user can create post only once
 */
function twiki_post_count() {
    $your_current_user_id = get_current_user_id();
    return count_user_posts( $your_current_user_id , "your-post-type-slug" , false );
}

3. Add function twiki_post_count then need to be added to Toolset > Settings > Front End Content > Functions inside conditional evaluations:

Adding function to be used in conditionals in Toolset

4. Then use conditional to restrict the content

[wpv-conditional if="( twiki_post_count() lt '1' )"]
 This user can add this post type currently. Toolset form will be displayed.
[/wpv-conditional]

You can also use this function in Oxygen Builder custom conditional PHP function value (without need to adding in toolset setting).

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

2 comments

  • Gabriel

    Hello, it is not working for me, it still shows the form.
    [wpv-conditional if=”( twiki_post_count() lt ‘1’ )”]

    is there a capital letter there?

  • A

    Hello Gabriel, are u using the right Quotes? Did you followed all steps? Point 3 is needed, do not forget!

    However, you can try if the function itself works with php. Add following code in PHP to your page:

    echo twiki_post_count();

    It should return the number of posts. If that works, then problem is something else. But I suggest to start with this test.

    regards, Aleš

Share Your Thoughts