Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>';  
    }
share|improve this question
    
Great that you solved your own problem. Could you please add it as an "answer" instead of editing this question? This way the question won't stay in the "Unanswered" list. –  Jan Fabry May 27 '11 at 13:38
add comment

1 Answer

up vote 0 down vote accepted

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>';  
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.