The global $post object is from the current query, so what you’re seeing is the expected behavior.
If you always want the shortcode to return the post_meta from ID = 1, then you should just hardcode that into the shortcode like in @Chris_O’s answer where you just save a variable that equals 1 and pass that to get_page()
.
However, it sounds like you’re looking for shortcode attributes. Try this:
// shortcode function
function testid_shortcode( $atts ) {
// extract the variables, if there is no ID attr, the default is 1
extract( shortcode_atts( array(
'id' => 1
), $atts ) );
// set page id to either the id attr which defaults to one.
$page_id = $id;
$page_data = get_page( $page_id );
return // ... return something with your shortcode
}
// register the shortcode
add_shortcode( 'testid', 'testid_shortcode' );
Then you could use:
[testid]
To return the post object with ID=1 or
[testid id=2]
to return the post object with ID=2.