Translations of this page:

Types of custom fields

Magic Fields 2.0 has 15 different types of fields (custom fields) that can be used, in this section we will go over each of them and their options if available.

 


 

Audio

The Audio field allows us to upload an audio file. Once the file has been uploaded and saved/updated the post will show an audio player where you can listen to the audio file.

These field can be displayed in two ways:

The first is to return the URL with the location of the audio file.

<?php
   echo get('field_name');
   // this returns something similar to: http://magic.local/wp-content/files_mf/1257808230JoyDivision-ShadowPlay.mp3
?>

The second is to print the same player showed in the administrator, this is achieved with the get_audio function. As showed bellow:

<?php echo get_audio('field_name'); ?>

 


 

Checkbox

As it name indicates it's a checkbox, this field returns a boolean value.

To show the value of the field in the template use:

<?php
$value = get('field_name');
if($value){  /*extra code*/ }
?>

 


 

Checkbox List

The Checkbox List field is a series of checkboxes where we can choose all the options we want. When we create a field this shows two Textareas, in “Options” we must place all the options that we want to show for the checkbox list, each value separated by a new line and “Default Value” as it name indicates the value to take when a new post/page is created.

This field returns an array of the chosen options.

To show the value of the field in the template use:

<?php
$values = get('field_name');
foreach($values as $value){
  printf('<p>%s</p>', $value );
}
?>

 


 

Color Picker

The Color Picker field lets us pick a color.

This field returns a string with the chosen color (in hexadecimal like #000000 o #808080).

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Date

The Date field lets us pick a date. In the options for this field it lets us chose the date format.

This field returns a string with the date format and the chosen date.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Dropdown List

The Dropdown field is also known as the select box, in the options for this field we can place all the elements that we want to show. We can choose a specific element to be selected by default. In addition to this we can chose to have multiple values.

This field returns the element or elements selected.

In case that we chose that it can only have one value in the field options we would use this code:

<?php echo get('field_name'); ?>

If we chose to have many values we would have to use this code:

<?php
$values = get('field_name');
foreach($values as $value){
  printf('<p>%s</p>',$value);
}
?>

 


 

File

The File field allows us to upload a file.

This field returns a URL with the file location uploaded.

To show the value of the field in the template use:

<?php echo get('field_name'); ?>

 


 

Image

The Image field allows us to upload an image, the options for this field lets us place the name of a CSS class for an image, Max Height, Max Width and Custom, these parameters will be used to generate the thumbnail when the get_image function is used, if the fields are empty it will return the original image.

This field returns a URL with the uploaded image.

To show the field value in the template use:

<?php
 echo get('field_name');
 // This would show something like this: http://magic.local/wp-content/files_mf/125780366410677912_gal.jpg
?>

Using the get_image funcion. This returns the HTML tag for an image. In this example the CSS class that we placed for the field was magicfields, with a Max Height of 100, Max Width of 100 and the custom field: zc=1 this will show an image with a size of 100 x 100 and with a zoom-crop.

<?php
 //using get_image
 echo get_image('field_name');
 //This is the code it will print:
 // <img src='http://magic.local/wp-content/files_mf/th_bf03ed07699f09100b6f3f35fe829808_125780366410677912_gal.jpg' class='magicfields'  />
?>

Note: To generate images with other features see the Front-End Functions section.

 


 

Image (Upload Media)

This field lets us chose an image that we have in the media library or an image that we want to upload and save in the media library in wordpress. The field is similar to the image field because it has the same options.

When we click on “Set Image” the classic Wordpress media window will open and we can upload the image or select one from the library. When the image finishes uploading or when you click on image details we can insert it into a field by clicking on the link “Insert into field” which will insert the image selected into the field.

This field just takes the image reference. When you erase an image form a field it erases the reference between the field and the image. In other words, the image stays intact in the media library. Another advantage is that you can modify the image with the image editor in Wordpress and these changes will be reflect in the image.

To get an image you can use the get_image function using it in the same way as in the Image field.

 


 

Markdown Textbox

The Markdown Textbox is a field similar to the Multiline Textbox. But the text is Markdown style. In other words we would see it as if it were HTML code. A toolbar will helps us format the text.

This field returns the textbox content.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Multiline Textbox

The Multiline Textbox is a Textarea that counts with a visual editor like the one used in the post area of Wordpress, this field has the same filters that are used in “the_content();” this field has two tabs to change the state from the visual editor (activate editor) to HTML (deactivate editor).

In both options of this field we can chose of we want to have the visual editor, if we chose we don't want the visual editor the field will show a normal Textarea.

This field returns a string of filters used for “the_content();”.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Radiobutton List

This field works similar to a checkbox list, in the field options it will show a textarea where we will place the options to be displayed for the field and the default value that the field will have.

This field returns the chosen radiobutton.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Related Type

The Related Type field is a special field that lets us select a post belonging to a Post Type, in the options for this field we can chose which the Post Type this will show only the Post Types related, then we can chose the order in which it will be arranged and by what field it will arrange the posts (ID or title).

This field returns the ID of the selected post.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Slider

The slider control lets us chose a value, in the options for this control we can assign the minimum value, maximum value and the size of each step of the control.

This field returns a string with the value selected.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>

 


 

Textbox

The textbox is a simple input, it returns a simple string.

To show the value of the field in your template use:

<?php echo get('field_name'); ?>
types_of_custom_fields_v20.txt · Last modified: 2011/08/02 12:56 by bcorona