I'm not sure if I have worded this question correctly, but basically I have the following array result from WordPress I am trying to deal with:
Array
(
[0] => WP_User Object
(
[data] => stdClass Object
(
[ID] => 3
[user_login] => Jean Gomes
[user_pass] => $P$BvW6LK9/blGKLuSj.9spNPW3.v104..
[user_nicename] => jean-gomes
[user_email] => jean.gomes@dpa.dev
[user_url] =>
[user_registered] => 2014-08-28 10:56:39
[user_activation_key] =>
[user_status] => 0
[display_name] => Jean Gomes
)
[ID] => 3
[caps] => Array
(
[author] => 1
)
[cap_key] => dpa2335327_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[wpseo_bulk_edit] => 1
[author] => 1
)
[filter] =>
)
[1] => WP_User Object
(
[data] => stdClass Object
(
[ID] => 4
[user_login] => Tammy Day
[user_pass] => $P$BejydpFxKDp60WruV71u0/JnJm9o.E.
[user_nicename] => tammy-day
[user_email] => tammy.day@dpa.dev
[user_url] =>
[user_registered] => 2014-08-28 10:57:23
[user_activation_key] =>
[user_status] => 0
[display_name] => Tammy Day
)
[ID] => 4
[caps] => Array
(
[author] => 1
)
etc
I would like to perform a foreach
using these results, for the ID.
E.g.
foreach ( $authors as $author_id ) {
But I don't know how to access the ID. I tried:
foreach ( $authors->ID as $author_id ) {
But obviously this can't work, as there is a number before that, is there an equivalent of:
foreach ( $authors['X']->ID as $author_id ) {
that I could use?
Sorry I know this is probably a silly question, but I'm quite stuck. I know I probably have to do a foreach within a foreach but I can't work out the syntax at all.
foreach ($authors as $author) { echo $author->ID; }
.