get_post_meta not working with variable as a post_id for dynamically get the postid September 19, 2022 by Tarik Billa You can try to add global $post; on top of your code. But it depends on where the function is called.