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?

    ihordeveloper

    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 🙁

    ihordeveloper

    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!

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

You must be logged in to reply to this topic.

Subscribe

Sign In

Don't have an account? Register

Forgot password?

Register

Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.