php - Secondary featured image as div background

one text

Solution:

I think what you are looking for is to get the URL of the secondary image, not the full post thumbnail.

In the documentation there is MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image');

https://github.com/voceconnect/multi-post-thumbnails/wiki/Frequently-Asked-Questions

So then on your page, you can do (Not the nicest):

    <?php 
 
if (class_exists('MultiPostThumbnails')) : 
 
image_url = MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image');
?>
<style>
.myclass{
background-image: url('<?php echo image_url ?>');

}
</style>
 <?php 
endif;
 
?>

Or you can add that image_url to the html div container:

<div style="background-image: url('<?php echo image_url ?>');">
</div>

Depends on how you have it setup

Source