Home Support General HivePress Make Image Compulsory

Make Image Compulsory

  • Author
    Posts
  • geokip

    Greetings, many thanks for this theme and plugins. They are beyond amazing. I have a question or two… How do I go about making images compulsory? They are currently set to optional. And can someone limit/increase the number and size of images to be uploaded?

    ihor developer

    Thanks! If you have a moment, please rate it on WP.org, it really helps to continue the development https://wordpress.org/support/plugin/hivepress/reviews/

    You can use this code snippet to require uploading at least 1 image, and change the maximum number of images that can be uploaded:

    add_filter(
    	'hivepress/v1/models/listing',
    	function( $model ) {
    		$model['fields']['images']['required']  = true;
    		$model['fields']['images']['max_files'] = 10;
    
    		return $model;
    	}
    );
    geokip

    Thank you for the feedback. I added the code but when I tried it out, the form just kept reloading. It did not give any alert/error whatsoever.

    geokip

    Is it the ‘image’ field or the ‘images’ field that should be made compulsory? Because if I tweak the above code and change the $model[‘fields’][‘images’][‘required’] = true; to $model[‘fields’][‘image’][‘required’] = true; the code seems to work. The downside is that the label field for images is still saying (optional). So that might confuse a user 🙁

    ihor developer

    There’s a new version of HivePress, please try updating and check if the above snippet works (I tested and fixed it while developing the latest version).

    ianantwalks

    I just wanted to say I tried the code with the latest theme version and it worked for me – thanks very much!

    dinesh123

    Hi,
    I have changed it to 4 max. but while testing I was able to upload 6 images.tried for two times.same results.Is it same code or modified now.Thanks.

    ihor developer

    Thanks, this is a bug that will be fixed https://hivepress.io/support/topic/limit-the-number-of-images-upload/

    Ann

    @geokip You can edit the word ‘images’ to ‘image’ using the LocoTranslate plugin. You’ll find the word in the Hivepress plugin. If you keep the word ‘images’ in the code snippet as it is, then ‘optional’ disappears. Hope that makes sense!

    Natiq

    Hi @Ihor
    In which file I must to add this code?

    add_filter(
    	'hivepress/v1/models/listing',
    	function( $model ) {
    		$model['fields']['images']['required']  = true;
    		$model['fields']['images']['max_files'] = 10;
    
    		return $model;
    	}
    );
    Natiq

    @Ihor Thank you I solved it

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘Make Image Compulsory’ is closed to new replies.