Custom Meta Image? What's that?
Do you mean that,
These are two very different things one of which is dealing with,
add_post_meta
the other,
wp_insert_attachment
The latter of which inserts attachments into your media library which is associated with your wp_posts
database table.
Post meta on the other hand (i.e. add_post_meta
etc) is associated with your wp_postmeta'
database table.
Attachments are actually classified as a post_type
just line post
or page
or your custom_post_type
for instance.
Attachments, as a post type, may or may not also then be associated with a Post's ID, stored as an integer in the post_parent
column in your wp_posts
database. If set to 0
, this means that the attachment has no parent and is not associated with any particular post.
Theory aside...
You may very well be trying to access an attachment that simply doesn't exist in the first place.
$attachment_id = 20; //example ID of the attachment you want to retrieve
$attachment = wp_get_attachment_image_src( $attachment_id );
echo $attachment[0];
The particular code above is useful for retrieving an attachment which is not associated with any particular post.
$post_id = 100; //example post ID
$attachment = wp_get_attachment_thumb_url( $post_id );
echo $attachment; //returns the URL of the image attached to the post
Where as retrieving an value, regardless of what that value is, when dealing with post meta (as you referred to as custom meta image) requires the use of,
get_post_meta
In use,
$post_id = get_the_ID();
$meta = get_post_meta($post_id, 'your_meta_key');
echo $meta;
API References
UPDATE
Based on your code,
$portfolio_image_one = get_post_meta( $post->ID, '_cmb_portfolio_image_one', true );
The post_meta value is held within your variable,
$portfolio_image_one
What you need to do is,
echo $portfolio_image_one;
Otherwise nothing is going to happen.
If there is a value stored for the meta_key
i.e. _cmb_portfolio_image_one
then by echoing the result of the variable, you shall be presented with your meta_value
whatever that value is, such as http://domain.com/my_image.jpg
for example.
If $post->ID is being used outside of the loop you will run into trouble, hence refer to my previous example, but with your code,
$post_id = get_the_ID();
$portfolio_image_one = get_post_meta($post_id, '_cmb_portfolio_image_one', true);
echo $portfolio_image_one;