Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you can do that either with the Custom Fields extension (https://wpadverts.com/extensions/custom-fields/) or using the Forms API.

    With the Forms API, you can add the code below in your theme functions.php file or even better create a new blank plugin (https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/) and paste the code there, it will require users to upload at least one file to the gallery

    
    add_filter( "adverts_form_load", "limit_file_uploads" );
    function limit_file_uploads( $form ) {
        if( $form['name'] != "advert" ) {
            return $form;
        }
        foreach( $form["field"] as $key => $field ) {
            if( $field["name"] != "gallery" ) {
                continue;
            }
    
            $form["field"][$key]["validator"] = array();
            $form["field"][$key]["validator"][] = array(
                "name" => "upload_limit",
                "params" => array( 
                    "min" => 1,     // minimum files to upload
                    "max" => 20     // maximum file uploads
                )
            );
            break;
        }
        return $form;
    }
    
    Thread Starter Nishant Patel

    (@nishantpatel121)

    Thanks again Greg.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Required Gallery images’ is closed to new replies.