tinoU
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
Latest version of Types is causing Error message/brake
Started by: tinoU in: Toolset Professional Support |
2 | 2 | 4 years ago | ||
CRED Form not sending immediately using Ajax submit
Started by: tinoU in: Toolset Professional Support |
2 | 11 | 5 years ago | ||
Types plugin crashes wordpress admin on activation
Started by: tinoU in: Toolset Professional Support |
2 | 4 | 6 years, 2 months ago | ||
Limit the number of CRED form Submissions
Started by: tinoU
in: Toolset Professional Support
Problem: I had followed your recommendation at https://toolset.com/forums/topic/limiting-cred-form-submission-to-one-post/# I have a CRED form (ID: 1695) which creates CPT Reviews (review) of another parent CPT Shops (shop) and I want to limit the number of reviews each user on my site submits, down to one review per shop. The user roles are as follows: Role 1: Author and I would like to show the same error message. Solution: You can add an author filter into the query, for example, //Limit the number of reviews for a user on a parent CPT add_filter('cred_form_validate','my_validation',10,2); function my_validation($field_data, $form_data) { //field data are field values and errors list($fields,$errors)=$field_data; //uncomment this if you want to print the field values //print_r($fields); //validate if specific form if ($form_data['id']==1695) { $user = get_current_user_id(); $shop_id = $_POST['_wpcf_belongs_shop_id']; $args = array( 'meta_key' => '_wpcf_belongs_shop_id', 'meta_value' => $shop_id, 'post_type' => 'review', 'author' => get_current_user_id() ); $query = new WP_Query( $args ); $user_post_count = 0; if(isset($query->found_posts)){ $user_post_count = $query->found_posts; } $user_data = get_userdata($user); $user_role = $user_data->roles; if ( in_array($user_role[0], array('subscriber', 'author', 'contributor', 'editor')) && $user_post_count > 0) { //set error message for my_field $errors['wpcf-user-validation']='<span><i class="fa fa-star" aria-hidden="true"></i> You have already left a Review!</span>'; } } //return result return array($fields,$errors); } Relevant Documentation: https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters |
2 | 9 | 6 years, 10 months ago |