Your issue is your foreach
loop. Because you don’t manually setup postdata, the current post object is not available in global scope, that is why you cannot make use of template tags or anything else for that matter that relies on the post object.
For get_the_author_meta()
to work in your current situation, you will have to explicitely pass the current post author to the function. Something like this will work
get_the_author_meta( 'ID', $item->post_author );
To avoid this, and to make proper use of template tags, setup postdata. For this to work, you will need to use the $post
global. Just remember to reset the $post
global back to the main query’s $post
value
foreach ( $items as $post ) {
setup_postdata( $post );
// Use normal template tags
the_title();
the_content();
echo get_the_author_meta( 'ID' );
}
wp_reset_postdata(); // VERY VERY IMPORTANT