Hi,
Based on my below function, I have some questions.
1. I have an edit form,
2. Is $_POST a wordpress global variable? If yes, why sometimes it needs to declare global $post before we use?
3. what is difference between $_POST and $post ?
4. what is difference between $form_data and $_Post?
My guess is that $form_data is the data haven't been saved into DB, it hasn't submit yet. However $_Post is saved.
5. Does any parameter passing to function are global variable? For example the parameters from below function.
6. How do I get the post id in below function? I tried $form_data['container_id'], get_post_id(), and they don't work.
7. what is the best way to see the value of the field while develop and debug?
function func_validate_custom_field($error_fields, $form_data){
//field data are field values and errors
list($fields,$errors)=$error_fields;
if ($form_data['id']==129 || $form_data['id']==310){
$args = array(
'meta_query' => array(
array('key' => 'wpcf-cf-url',
'value' => trim($_POST['wpcf-cf-url'])
)),
'post_type' => 'unwrap',
'posts_per_page' => -1
);
$posts = get_posts($args);
if (count($posts) > 0){
$ori_posts_id = $posts[0]->ID;
$ori_url = get_permalink( $ori_posts_id );
//set error message for my_field
$click_url = ' Click Me ';
$errors['wpcf-cf-url']= 'This wine has been posted. Go to the page. ' .$click_url ;
}
}
return array($fields,$errors);
}
add_filter('cred_form_validate','func_validate_custom_field',10,2);