I'm trying to use code to show custom field outside the loop in wordpress attachment page (image.php) it's returns nothing.
this is the code i'm used to show the custom field:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'my-custom-field', true);
?>
and i'm trying to show parent post id in attachment page too
with get_the_id and use this code
<?php global $wp_query;
$this_page_id = $wp_query->post_parent;
$post_id = get_the_id($post->ID);
echo $post_id ;?>
but the code above just shown the attachment ID not the parent post ID. anyone can help, please ?