aw2.upload
This shortcode is used to handle file uploads for our awesome forms. aw2.upload shortcode also allows you to easily set an uploaded image as featured image, or as part of WooCommerce product image gallery.
Attributes:
- main:
attach_to_post | upload_to_path‘attach_to_post’ allows you to attach the uploaded file to given post_id, while ‘upload_to_path’ allows you to move the file to a specified directory. - post_id:
ID of the post to which you want to attach the uploaded file in WordPress. It is required for upload to work properly.
- upload_element_id:
This has to be the ‘name’ attribute of the file tag as it is used to identify the $_FILE element within the form. When set_featured is false, the attachment id of the file is stored within post meta as specified “upload_element_id” as the key. This is required.
- upload_file_url:
If you want to store actual file URL as well for the uploaded file element you can specify the meta key using upload_file_url attribute.
- dir_name:
If you want to upload a file outside of uploads dir, you can specify the folder path using dir_name.
- file_name:
If you are using upload_to_path main attribute then you have to specify the file_name to use for uploading the file.
- overwrite_file/span>
yes | noBy default when the file is uploaded using aw2.upload it gets overwritten for upload_to_path. If you want you can set overwrite_file to no and if the file already exists then it automatically gets renamed by appending number a number it. - allowed_file_types:
If you want to restrict the file uploads to certain file types then you can specify the comma-separated list of extensions using allowed_file_types.
- set_featured:
True | FalseIf set_featured is set to true, it will set the uploaded image to featured image for the post. If true it will not store the attachment id within the upload_element_id key. By default it is false. - woo_product_gal:
True | FalseIf specified as true, all the uploaded images are saved to WooCommerce product image gallery. It can only be used with attach_to_post main attribute
Examples of using aw2.upload:
Using attach_to_post to upload an image to the media library.
[aw2.upload post_id='1' attach_to_post upload_element_id='file' set="module.image_id" /] [aw2.get attachment_url attachment_id='{module.image_id}' /]
Using woo_product_gal attribute with aw2.upload shortcode
[aw2.upload post_id='{{aw2.get request.product|post|ID}}' attach_to_post upload_element_id='product_featured' set_featured=true /] dummy [aw2.upload post_id='{{aw2.get request.product|post|ID}}' attach_to_post upload_element_id='product_gal' woo_product_gal=true /]
Using upload_to_path attribute
[aw2.upload upload_to_path upload_element_id="{request.ele_id}" dir_name="uploads/{request.dir_name}" file_name="{request.file_name}" overwrite_file='yes' json_encode=true /]
Other shortcodes
Conditionals (7)
Core (11)
- aw2.run
- aw2.return
- aw2.template
- aw2.module
- aw2.raw
- aw2.get
- aw2.set_array
- aw2.set
- aw2.echo
- aw2.shortcode
- aw2.part
CRM (1)
Database (1)
Design & JavaScript (3)
- aw2.enqueue
- aw2.client
- aw2.spa
E-commerce (1)
Excelsheet (1)
- excel.write_bulk
Form Handling (3)
- aw2.sideload
- aw2.save_form
- aw2.upload
Mailing & SMS (3)
- aw2.subscribe
- aw2.sms
- aw2.wp_mail
PDF (1)
Utility (6)
- aw2.register
- aw2.register_handler
- aw2.reset_password
- aw2.login_handler
- app.restore
- app.backup
Latest Blogs
And there’s one thing I keep noticing: Everyone's obsessed with growth hacks.