Viewing 3 replies - 1 through 3 (of 3 total)
  • Good idea.

    Plugin Author Greg Winiarski

    (@gwin)

    Try adding this code in your theme functions.php or even better create a new plugin and paste the code there

    define("LIMIT_FILE_UPLOADS", 2);
    
    add_filter("adverts_gallery_upload_prefilter", "limit_file_uploads");
    
    function limit_file_uploads( $file ) {
    
        if ( !isset($file["name"]) || !isset($file["type"]) ) {
            return $file;
        }
    
        if ( !isset( $_POST["post_id"] ) ) {
            $post_id = 0;
        } else {
            $post_id = intval($_POST["post_id"]);
        }
    
        if( $post_id < 1 ) {
            // first image upload.
            return $file;
        }
    
        $attachments = get_children( array( 'post_parent' => $post_id ) );
        $images = count( $attachments );
    
        if( $images >= LIMIT_FILE_UPLOADS ) {
            $file["error"] = sprintf( "You cannot upload more than %d images.", LIMIT_FILE_UPLOADS );
        }
    
        return $file;
    }

    In the first line change define("LIMIT_FILE_UPLOADS", 2); change 2 to max number of images (per ad) you want users to be able to upload.

    Thread Starter iFever

    (@ifever)

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Set a Maximum Upload Images in WordPress?’ is closed to new replies.