Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Validate CRED Forms check duplicates of current user by title */
- add_filter('cred_form_validate','func_validate_title',10,2);
- function func_validate_title($error_fields, $form_data){
- list($fields,$errors)=$error_fields;
- $forms_array = array( 48 );
- if (in_array($form_data['id'], $forms_array)) {
- // get current user and title
- $current_user = wp_get_current_user();
- $title = $_POST['post_title'];
- // query to get the posts to compare
- $args = array( "author" => $current_user->ID, "post_type" => "add", "posts_per_page" => -1, "post_status" => array('publish', 'draft') );
- $query = get_posts( $args );
- if (count($query) > 0){
- //set error message for the title field if a post of the same title exists
- foreach ($query as $post) {
- if (strtolower($post->post_title) == strtolower($title)) {
- $errors['post_title']='Найден дубликат в Ваших объявлениях. Проверьте Личный кабинет > Объявления > Неактивные.';
- break;
- }
- }
- }
- }
- //return result
- return array($fields,$errors);
- }
Add Comment
Please, Sign In to add comment