EDIT SOLUTION
Managed to fix the problem
Special thanks to bynicolas for getting me in the right direction!
Plugin code:
<?php
// function to show a banner using query of banner post type
function show_banner( $att ) {
// Set default $att values if none is provided
// $att is an array so access the shortcode value via $att['thumbnail_id']
// in the [banner thumbnail_id="12"] shortcode
$atts = shortcode_atts(
array(
'_thumbnail_id' => '',
), $atts, 'banner' );
//print_r('Thumbnail_id: ' . $att['_thumbnail_id'] . '<br>');
//start by setting up the query
$get_banner = new WP_Query( array(
'post_type' => 'banners',
)
);
//now check if the query has posts and if so, output their content in a banner-box div
if ( $get_banner->have_posts() ) :
while ( $get_banner->have_posts() ) : $get_banner->the_post();
$thumbnail_id = get_post_meta(get_the_ID(), '_thumbnail_id', true);
$image_url = get_post_meta(get_the_ID(), 'banner_link', true);
$target = get_post_meta(get_the_ID(), 'target', true);
if ($thumbnail_id === $att['_thumbnail_id']) {
// print_r($thumbnail_id . ' ');
// print_r($image_url . ' ');
// print_r($target . '<br>');
$output = '<div class="container" align="center"><a href="'.get_post_meta( get_the_ID(), 'banner_link', true ).'"
target="'.get_post_meta( get_the_ID(), 'target', true).'">'.get_the_post_thumbnail().
'</a></div>';
}
endwhile;
endif;
wp_reset_postdata();
return $output;
}
add_shortcode( 'banner', 'show_banner' );
?>
Page.php
<?php echo do_shortcode('[banner _thumbnail_id="584"]');?>
//584 is the thumbnail_id, so change that to your own thumbnail_id.