I have a custom front end page where users can post from. All works fine but the i want if more than one field is empty then the errors for all empty fields should show all together. Right now the code only show error for the first empty field it detects. The code is :
$errors = new WP_Error();
if (isEmptyString($title_stripped))
$errors->add('empty_title', __('Please enter a title'));
if (isEmptyString($description_stripped))
$errors->add('empty_desc', __('Enter a breif description'));
if (isEmptyString($content_stripped))
$errors->add('empty_content', __('Please enter your article here'));
return $errors;
Edit : Solved
Sorry to bother . It was one of my other functions which was limiting the error to echo only once. Here is the previous code :
function display_message( $message = false ) {
if( is_wp_error( $message ) ) {
echo '<div class="error"><p>' . $message->get_error_message() . '</p></div>';
}
It worked fine when i changed it too :
function display_message( $message = false ) {
if( is_wp_error( $message ) ) {
echo '<div class="error"><p>';
foreach ( $message->get_error_messages($code) as $error ) {
echo $error . "<br />n";
}
echo '</p></div>';
}
Sorry to bother . It was one of my other functions which was limiting the error to echo only once. Here is the previous code :
It worked fine when i changed it too :