Title: Why does WP_Error::get_error_message() get first message?
Last modified: April 25, 2017

---

# Why does WP_Error::get_error_message() get first message?

 *  [xoogu](https://wordpress.org/support/users/xoogu/)
 * (@xoogu)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/why-does-wp_errorget_error_message-get-first-message/)
 * I was wondering what the reasoning was as to why WP_Error::get_error_message()
   gets the first error message, as opposed to the most recent error message?
 * To me it would seem more sensible if it retrieved the most recent one.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/why-does-wp_errorget_error_message-get-first-message/#post-9067764)
 * I’ve no special insight into the logic behind why core developers do things, 
   but I think it is mainly a convenience method. There are many situations where
   there will only be one message, if any. Thus this method saves you from needing
   to fuss with getting the zeroth element from the error object. Yeah, it’s not
   a big deal to get such an element, but novice coders are easily confused by complex
   data structures. If all you need is the one message, your code is not cluttered
   by additional code to extract the message. I for one appreciate uncluttered code.
 * If you have greater needs where there may be multiple errors, you are free to
   use WP_Error::get_error_messages() to get either all messages or those of a particular
   code.
 *  [djeyewater](https://wordpress.org/support/users/djeyewater/)
 * (@djeyewater)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/why-does-wp_errorget_error_message-get-first-message/#post-9067793)
 * What I mean, is why did they choose to get the first message though? They could
   have just as easily decided to return the last message.
 * Was it just something that was done without much thought, and then has been kept
   that way for compatibility reasons? Or is there some good reason that you’d more
   likely want the first message rather than the last one?
 * PS I’m the OP, I must have signed in with one of my other a/cs by accident.
    -  This reply was modified 9 years, 1 month ago by [djeyewater](https://wordpress.org/support/users/djeyewater/).
      Reason: clearing up that I'm the OP
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/why-does-wp_errorget_error_message-get-first-message/#post-9068118)
 * Thanks for clarifying who you are, that would have been confusing. Different 
   account and even different IP. Please try to be consistent with which account
   you use. While there are perfectly legitimate reasons for multiple accounts, 
   they can also cast a great deal of suspicion upon yourself. Some misguided plugin
   and theme authors create multiple accounts so they can tell themselves how great
   their product is. Such behavior is not tolerated at all and it will not end well
   for them.
 * As I’ve no insight to why core devs do things, I can’t accurately answer. Going
   off my thought that it’s a method of convenience for situations where only one
   error can possibly occur, the first message happens to be the last message as
   well. So in that context they _are_ showing the last message 😛
 * The bottom line is if you need the last message of several, you are using the
   wrong method. You want WP_Error::get_error_messages() — the one with an extra
   S for the plural form of message.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Why does WP_Error::get_error_message() get first message?’ is closed 
to new replies.

## Tags

 * [wp_error](https://wordpress.org/support/topic-tag/wp_error/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/why-does-wp_errorget_error_message-get-first-message/#post-9068118)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
