A Cozmoslabs Product
Documentation / Custom Fields Creator / Upload Custom Field

Upload Custom Field

Overview

This Default Field Type is available in WordPress Creation Kit free version. The Upload Field creates a file upload form. It can be used to upload images, videos, PDFs etc. and uses the default WordPress Media Uploader.

Creating an Upload Field

To add an Upload Field to a previously created Custom Meta Box, under the Meta Box Fields tab simply insert a Field Title and under Field Type make sure you select Upload.

WordPress Creation Kit - Custom Fields Creator - Meta Box Fields - Upload Field

The Upload Field contains options to customize it:

  1. Description – Allows you to specify a description for the Upload Field
  2. Required – Select whether the field is required or not
  3. Default Value – Set a default value for the Upload Field
  4. Attach upload to post – Whether or not the upload should be attached to the post

Page, Post or Custom Post Type Edit Screen

This is how the Upload Field we created above looks like in the Edit Screen:

WordPress Creation Kit - Custom Fields Creator - Meta Box Fields - Upload Field (Editor)

Template usage

The following examples are for a Custom Meta Box with the “Group Name” argument “my_meta_name“. Make sure to replace this with the “Group Name” you have set up. The Custom Meta Box below is setup to be attached to a post.

WordPress Creation Kit - Custom Fields Creator - Meta Box Arguments - Template

Using the WCK Custom Fields API

The Upload Field returns the source string, the attachment post object or, for a image upload, an array with the image details.

For a Single Meta Box

To output a value inside the loop we use the function the_cfc_field() which echoes the src of the upload


To assign the value to a variable we use the function get_cfc_field() which for the Upload Field return the attachment post object or, for a image upload, an array with the image details:

Notice: We’re returning an array for image uploads and an attachment object for other file types (like PDF, CSV, etc.)

 


For a Repeater Meta Box

To output all the “Avatar” entries from the repeater field we use the functions get_cfc_meta() and the_cfc_field():

"/>

To output a specific “Avatar” entry from the repeater field, for example the second entry, we use the function the_cfc_field():


The index starts at 0 so that’s why we pass “1” to the function. For the first entry it would be “0”, the second is “1”, the third is “2” and so on…

Using the WordPress default functions

The Upload Field returns the attachment id.

For a Single Meta Box

'; 
}
?>

For a Repeater Meta Box

To output all the “Avatar” entries in the repeater field:

';
    }
}
?>

To output a specific “Avatar” entry from the repeater field, for example the second entry:

';
}
?>

The index starts at 0 so that’s why we pass “1” to the function. For the first entry it would be “0”, the second is “1”, the third is “2” and so on…

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket