I've got two foreach loops, and I'm using an object generated by WordPress.
In my mind, these should both work the same. However, they don't. Notice $post and $not_a_post in the loop:
A:
$array_A = array( 'posts_per_page' => 2 );
$get_posts_A = get_posts( $array_A );
foreach ( $get_posts_A as $post ) { //uses $post
the_title();
}
B:
$array_B = array( 'posts_per_page' => 5 );
$get_posts_B = get_posts( $array_B );
foreach ( $get_posts_B as $not_a_post ) { //uses $not_a_post
the_title();
}
The only difference is that I use a variable $post for conditional first loop.
I always thought (apparently, incorrectly) the second conditional variable was just a placeholder. So I could do $x, $y, etc.
Can someone explain to me why this foreach loop requires the variable $post ?
foreachloop has the variable$postavailable inside it, the second has$not_a_post. Who knows whatget_postsdoes orthe_title()requires, as you don't show us that code.