WordPress uses a global $post
to keep track of the current post the user is viewing. Whenever you call functions like the_title()
or get_the_ID()
it uses that global $post
to pull that data. In your code snippet you’re using get_posts()
which generally does not overwrite the global $post
object unless you specify with setup_postdata( $post )
.
The easiest thing to do is to simply modify your metadata line and use:
$custom_meta_writer = get_post_meta( $post->ID, 'writer_meta_key', true );