Different number of images depending on featured status

Hello everyone,

I would like to implement on my website that a provider can add 5 photos to an entry by default. The moment an entry receives “featured” status, it should be possible to add up to 25 photos.

I do not use the Paid Listings add-on.

I know this requires customization and I’m already working with a developer.

Is my project fundamentally possible and if so, what is the right approach?

Hi,

This depends on how the featured status is implemented. If it’s a custom checkbox attribute with “featured” name, you can try using this code snippet Change the maximum number of images per listing #hivepress #listings · GitHub and adjust the maximum number of images based on the checkbox value. You can also use the hivepress/v1/models/listing/fields hook where the listing ID is already available so you can fetch its data.

Hope this helps

Hi ihor,

thank you very much. However, it’s not exactly what I meant. I am talking about the “featured” checkbox in the wordpress backend. The moment I check this box I want the different number of images to apply to a featured listing


.

Please try following the same suggestions, you can use the hivepress/v1/models/listing/fields hook, and get the featured status via the listing ID (it’s available for this hook), changing the limit for the images field. Here’s a similar code snippet Change the maximum number of images per listing #hivepress #listings · GitHub

Thank you very much ihor! I am using the following code, however it doesn’t seem to work (even if the listing is featured, the maximum upload of 5 pictures applies):

add_filter(
    'hivepress/v1/models/listing/fields',
    function( $fields, $listing_id ) {
        
        $fields['images']['max_files'] = 5;

       
        $listing = get_post($listing_id);

        
        if ( $listing && has_term( 'featured', 'listing_status', $listing_id ) ) {
            
            $fields['images']['max_files'] = 20;
        }

        return $fields;
    },
    100,
    2
);

What is wrong about my approach?

Please try checking the featured status this way:

if(get_post_meta($listing_id, 'hp_featured, true)) {
    $fields['images']['max_files'] = 20;
}

Then using get_post may not be needed.

Amazing! Worked. Thank you very much :slight_smile: