Custom Field Template Shortcodes

Below, you’ll find a detailed guide on how to add the Custom Field Template Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Custom Field Template Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Custom Field Template Plugin and the shortcodes it provides:

Plugin Icon
Custom Field Template

"Custom Field Template is a powerful WordPress plugin that allows you to easily create and manage custom fields. With its user-friendly interface, you can add extra functionality to your website."

★★★★✩ (23) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [cft]
  • [cftsearch]

Custom Field Template [cft] Shortcode

The Custom Field Template shortcode is a powerful tool that allows users to output custom field values. It provides a flexible way to display metadata associated with posts, including images, lists, and formatted text. The shortcode uses a variety of parameters, including ‘post_id’, ‘template’, ‘format’, and ‘key’, to customize the output. It can handle multiple values, sort data, and even apply PHP functions to the output. Furthermore, it supports conditional output and nested shortcodes, making it a versatile tool for WordPress developers.

Shortcode: [cft]

Parameters

Here is a list of all possible cft shortcode parameters and attributes:

  • post_id – Identifies the post to retrieve custom fields from.
  • template – Specifies the template to use for displaying custom fields.
  • format – Defines the format in which the custom fields are displayed.
  • key – The key of the specific custom field to display.
  • single – If set to true, only the first value of the custom field is displayed.
  • before_list – Text or HTML to display before the list of custom fields.
  • after_list – Text or HTML to display after the list of custom fields.
  • before_value – Text or HTML to display before each custom field value.
  • after_value – Text or HTML to display after each custom field value.
  • image_size – Defines the size of the image if the custom field is an image.
  • image_src – If set to true, the source URL of the image is displayed.
  • image_width – If set to true, the width of the image is displayed.
  • image_height – If set to true, the height of the image is displayed.
  • value_count – If set to true, the number of values in the custom field is displayed.
  • value – Specifies a specific value to display from the custom field.

Examples and Usage

Basic example – Display custom field values using the post id and key attributes

[cft post_id=1 key="custom_field_key" /]

Advanced examples

Display custom field values using the post id, key, and template attributes. The template attribute allows you to specify a custom template for the output.

[cft post_id=1 key="custom_field_key" template=1 /]

Display a single custom field value using the post id, key, and single attributes. The single attribute is set to true to return only the first value of the custom field.

[cft post_id=1 key="custom_field_key" single=true /]

Display an image from a custom field using the post id, key, and image_size attributes. The image_size attribute allows you to specify the size of the image.

[cft post_id=1 key="custom_field_key" image_size="thumbnail" /]

Display custom field values with a custom format using the post id, key, and format attributes. The format attribute allows you to specify a custom format for the output.

[cft post_id=1 key="custom_field_key" format="custom_format" /]

Display the count of a specific value in a custom field using the post id, key, value_count, and value attributes. The value_count attribute is set to true and the value attribute specifies the value to count.

[cft post_id=1 key="custom_field_key" value_count=true value="specific_value" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [cft] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cft', array(&$this, 'output_custom_field_values') );

Shortcode PHP function:

function output_custom_field_values($attr) {
		global $post;
		$options = $this->get_custom_field_template_data();
		
		if ( empty($post->ID) ) $post_id = get_the_ID();
		else $post_id = $post->ID;

		if ( !isset($options['custom_field_template_before_list']) ) $options['custom_field_template_before_list'] = '<ul>';
		if ( !isset($options['custom_field_template_after_list']) ) $options['custom_field_template_after_list'] = '</ul>';
		if ( !isset($options['custom_field_template_before_value']) ) $options['custom_field_template_before_value'] = '<li>';
		if ( !isset($options['custom_field_template_after_value']) ) $options['custom_field_template_after_value'] = '</li>';

		if ( !empty($attr['post_id']) ) $this->format_post_id = $attr['post_id'];
		if ( empty($attr['post_id']) && $this->format_post_id ) $post_id = $this->format_post_id;

		extract(shortcode_atts(array(
			'post_id'   => $post_id,
			'template'  => 0,
			'format'    => '',
			'key'   => '',
			'single'    => false,
			'before_list' => $options['custom_field_template_before_list'],
			'after_list' => $options['custom_field_template_after_list'],
			'before_value' => $options['custom_field_template_before_value'],
			'after_value' => $options['custom_field_template_after_value'],
			'image_size' => '',
			'image_src' => false,
			'image_width' => false,
			'image_height' => false,
			'value_count' => false,
			'value' => ''
		), $attr));
		
		$metakey = $key;
		$output = '';
		if ( $metakey ) :
			if ( $value_count && $value ) :
				return number_format($options['value_count'][$metakey][$value]);
			endif;		
			$metavalue = $this->get_post_meta($post_id, $key, $single);
			if ( !is_array($metavalue) ) $metavalue = array($metavalue);
			if ( $before_list ) : $output = $before_list . "\n"; endif;
			foreach ( $metavalue as $val ) :
				if ( !empty($image_size) ) :
					if ( $image_src || $image_width || $image_height ) :
						list($src, $width, $height) = wp_get_attachment_image_src($val, $image_size);
						if ( $image_src ) : $val = $src; endif;
						if ( $image_width ) : $val = $width; endif;
						if ( $image_height ) : $val = $height; endif;
					else :
						$val = wp_get_attachment_image($val, $image_size);
					endif;
				endif;
				$output .= (isset($before_value) ? $before_value : '') . $val . (isset($after_value) ? $after_value : '') . "\n";
			endforeach;
			if ( $after_list ) : $output .= $after_list . "\n"; endif;
			return do_shortcode($output);
		endif;

		if ( is_numeric($format) && !empty($options['shortcode_format'][$format]) && $output = $options['shortcode_format'][$format] ) :
			$data = $this->get_post_meta($post_id);
			$output = stripcslashes($output);
			
			if( $data == null)
				return;

			$count = count($options['custom_fields']);
			if ( $count ) :
				for ($i=0;$i<$count;$i++) :
					$fields = $this->get_custom_fields( $i );
					foreach ( $fields as $field_key => $field_val ) :					
						foreach ( $field_val as $key => $val ) :
							$replace_val = '';
							if ( isset($data[$key]) && count($data[$key]) > 1 ) :
								if ( isset($val['sort']) && $val['sort'] == 'asc' ) :
									sort($data[$key]);
								elseif ( isset($val['sort']) && $val['sort'] == 'desc' ) :
									rsort($data[$key]);
								endif;
								if ( $before_list ) : $replace_val = $before_list . "\n"; endif;
								foreach ( $data[$key] as $val2 ) :
									$value = $val2;
									if ( isset($val['outputCode']) && is_numeric($val['outputCode']) ) :
										eval(stripcslashes($options['php'][$val['outputCode']]));
									endif;
									if ( isset($val['shortCode']) && $val['shortCode'] == true ) $value = do_shortcode($value);
									$replace_val .= $before_value . $value . $after_value . "\n";
								endforeach;
								if ( $after_list ) : $replace_val .= $after_list . "\n"; endif;
							elseif ( isset($data[$key]) && count($data[$key]) == 1 ) :
								$value = $data[$key][0];
								if ( isset($val['outputCode']) && is_numeric($val['outputCode']) ) :
									eval(stripcslashes($options['php'][$val['outputCode']]));
								endif;
								if ( isset($val['shortCode']) && $val['shortCode'] == true ) $value = do_shortcode($value);
								$replace_val = $value;
								if ( isset($val['singleList']) && $val['singleList'] == true ) :
									if ( $before_list ) : $replace_val = $before_list . "\n"; endif;
									$replace_val .= $before_value . $value . $after_value . "\n";
									if ( $after_list ) : $replace_val .= $after_list . "\n"; endif;
								endif;
							else :
								if ( isset($val['outputNone']) ) $replace_val = $val['outputNone'];
								else $replace_val = '';
							endif;
							if ( isset($options['shortcode_format_use_php'][$format]) )
								$output = $this->EvalBuffer($output);
								
							$key = preg_quote($key, '/');
							$replace_val = str_replace('\\', '\\\\', $replace_val); 
							$replace_val = str_replace('$', '\$', $replace_val); 
							$output = preg_replace('/\['.$key.'\]/', $replace_val, $output);
						endforeach;
					endforeach;
				endfor;
			endif;
		else :
			$fields = $this->get_custom_fields( $template );
					
			if( $fields == null)
				return;

			$output = '<dl class="cft cft'.$template.'">' . "\n";
			foreach ( $fields as $field_key => $field_val ) :					
				foreach ( $field_val as $key => $val ) :
					if ( isset($keylist[$key]) && $keylist[$key] == true ) break;
					$values = $this->get_post_meta( $post_id, $key );
					if ( $values ):
						if ( isset($val['sort']) && $val['sort'] == 'asc' ) :
							sort($values);
						elseif ( isset($val['sort']) && $val['sort'] == 'desc' ) :
							rsort($values);
						endif;
						if ( isset($val['output']) && $val['output'] == true ) :
							foreach ( $values as $num => $value ) :
								$value = str_replace('\\', '\\\\', $value); 
								if ( isset($val['outputCode']) && is_numeric($val['outputCode']) ) :
									eval(stripcslashes($options['php'][$val['outputCode']]));
								endif;
								if ( empty($value) && $val['outputNone'] ) $value = $val['outputNone'];
								if ( isset($val['shortCode']) && $val['shortCode'] == true ) $value = do_shortcode($value);			
								if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) )
									$key_val = stripcslashes($val['label']);
								else $key_val = $key;
								if ( isset($val['hideKey']) && $val['hideKey'] != true && $num == 0 )
									$output .= '<dt>' . $key_val . '</dt>' . "\n";
								$output .= '<dd>' . $value . '</dd>' . "\n";
							endforeach;
						endif;
					endif;
					$keylist[$key] = true;
				endforeach;
			endforeach;
			$output .= '</dl>' . "\n";
		endif;

		return do_shortcode(stripcslashes($output));
	}

Code file location:

custom-field-template/custom-field-template/custom-field-template.php

Custom Field Template [cftsearch] Shortcode

The Custom Field Template shortcode is a powerful tool that allows you to search custom field values. It creates a search form on your WordPress site where users can search for specific custom field values. The shortcode is highly customizable, allowing you to define the search label, button, and format. It supports various field types like text, checkbox, radio, and select. The resulting output can be further customized with PHP code.

Shortcode: [cftsearch]

Parameters

Here is a list of all possible cftsearch shortcode parameters and attributes:

  • template – Numeric value representing the custom field template
  • format – Specifies the formatting of the template
  • search_label – Customizes the text for the search button
  • button – Boolean value to determine if a search button is displayed

Examples and Usage

Basic example – Displaying a custom search form using the ‘cftsearch’ shortcode.

[cftsearch template=1 format=1 search_label="Find"]

Advanced examples

Creating a custom search form with the ‘cftsearch’ shortcode, specifying the template, format, search label, and choosing not to display the search button.

[cftsearch template=2 format=2 search_label="Search" button=false]

Using the ‘cftsearch’ shortcode to create a custom search form, specifying the template, format, and customizing the search label.

[cftsearch template=3 format=3 search_label="Find Posts"]

PHP Function Code

In case you have difficulties debugging what causing issues with [cftsearch] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cftsearch', array(&$this, 'search_custom_field_values') );

Shortcode PHP function:

function search_custom_field_values($attr) {
		global $post;
		$options = $this->get_custom_field_template_data();

		extract(shortcode_atts(array(
			'template'    => 0,
			'format'      => '',
			'search_label' => __('Search &raquo;', 'custom-field-template'),
			'button'      => true
		), $attr));
		
		if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
			$output = stripcslashes($output);
			$output = '<form method="get" action="'.get_option('home').'/" id="cftsearch'.(int)$format.'">' . "\n" . $output;

			$count = count($options['custom_fields']);
			if ( $count ) :
				for ($t=0;$t<$count;$t++) :
					$fields = $this->get_custom_fields( $t );
					foreach ( $fields as $field_key => $field_val ) :
						foreach ( $field_val as $key => $val ) :
							unset($replace);
							$replace[0] = $val;

							$search = array();
							if( isset($val['searchType']) ) eval('$search["type"] =' . stripslashes($val['searchType']));
							if( isset($val['searchValue']) ) eval('$search["value"] =' . stripslashes($val['searchValue']));
							if( isset($val['searchOperator']) ) eval('$search["operator"] =' . stripslashes($val['searchOperator']));
							if( isset($val['searchValueLabel']) ) eval('$search["valueLabel"] =' . stripslashes($val['searchValueLabel']));
							if( isset($val['searchDefault']) ) eval('$search["default"] =' . stripslashes($val['searchDefault']));
							if( isset($val['searchClass']) ) eval('$search["class"] =' . stripslashes($val['searchClass']));
							if( isset($val['searchSelectLabel']) ) eval('$search["selectLabel"] =' . stripslashes($val['searchSelectLabel']));
							
							foreach ( $search as $skey => $sval ) :
								$j = 1;
								foreach ( $sval as $sval2 ) :
									$replace[$j][$skey] = $sval2;
									$j++;
								endforeach;
							endforeach;
												
							foreach( $replace as $rkey => $rval ) :				
								$replace_val[$rkey] = "";
								$class = "";
								$checked = "";
								$default = array();
								switch ( $rval['type'] ) :
									case 'text':
									case 'textfield':
									case 'textarea':
										if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; 
										$replace_val[$rkey] .= '<input type="text" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . (isset($_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0]) ? esc_attr($_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0]) : '') . '"' . $class . ' />';
										break;		
									case 'checkbox':
										if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; 
										$values = $valueLabel = array();
										if ( $rkey != 0 )
											$values = explode( '#', $rval['value'] );
										else
											$values = explode( '#', $rval['originalValue'] );
										$valueLabel = isset($rval['valueLabel']) ? explode( '#', $rval['valueLabel'] ) : array();
										$default = isset($rval['default']) ? explode( '#', $rval['default'] ) : array();
										if ( isset($rval['searchCode']) && is_numeric($rval['searchCode']) ) :
											eval(stripcslashes($options['php'][$rval['searchCode']]));
										endif;
										if ( count($values) > 1 ) :
											$replace_val[$rkey] .= '<ul' . $class . '>';
											$j=0;
											foreach( $values as $metavalue ) :
												$checked = '';
												$metavalue = trim($metavalue);
												if ( isset($_REQUEST['cftsearch']) && is_array($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) :
													if ( in_array($metavalue, $_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) )
														$checked = ' checked="checked"';
													else
														$checked = '';
												endif;
												if ( in_array($metavalue, $default) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey] )
													$checked = ' checked="checked"';

												$replace_val[$rkey] .= '<li><label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metavalue) . '"' . $class . $checked . '  /> ';			
												if ( isset($valueLabel[$j]) ) $replace_val[$rkey] .= stripcslashes($valueLabel[$j]);
												else $replace_val[$rkey] .= stripcslashes($metavalue);
												$replace_val[$rkey] .= '</label></li>';
												$j++;
											endforeach;
											$replace_val[$rkey] .= '</ul>';
										else :
											if ( isset($_REQUEST['cftsearch']) && $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == esc_attr(trim($values[0])) )
												$checked = ' checked="checked"';
											$replace_val[$rkey] .= '<label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr(trim($values[0])) . '"' . $class . $checked . ' /> ';			
											if ( $valueLabel[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabel[0]));
											else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
											$replace_val[$rkey] .= '</label>';
										endif;
										break;
									case 'radio':
										if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; 
										$values = explode( '#', $rval['value'] );
										$valueLabel = isset($rval['valueLabel']) ? explode( '#', $rval['valueLabel'] ) : array();
										$default = isset($rval['default']) ? explode( '#', $rval['default'] ) : array();
										if ( isset($rval['searchCode']) && is_numeric($rval['searchCode']) ) :
											eval(stripcslashes($options['php'][$rval['searchCode']]));
										endif;
										if ( count($values) > 1 ) :
											$replace_val[$rkey] .= '<ul' . $class . '>';
											$j=0;
											foreach ( $values as $metavalue ) :
												$checked = '';
												$metavalue = trim($metavalue);
												if ( isset($_REQUEST['cftsearch']) && is_array($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) :
													if ( in_array($metavalue, $_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) )
														$checked = ' checked="checked"';
													else
														$checked = '';
												endif;
												if ( in_array($metavalue, $default) && (isset($_REQUEST['cftsearch']) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) )
													$checked = ' checked="checked"';
												$replace_val[$rkey] .= '<li><label><input type="radio" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metavalue) . '"' . $class . $checked . ' /> ';			
												if ( isset($valueLabel[$j]) ) $replace_val[$rkey] .= stripcslashes(trim($valueLabel[$j]));
												else $replace_val[$rkey] .= stripcslashes($metavalue);
												$replace_val[$rkey] .= '</label></li>';
												$j++;
											endforeach;
											$replace_val[$rkey] .= '</ul>';
										else :
											if ( isset($_REQUEST['cftsearch']) && $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == esc_attr(trim($values[0])) )
												$checked = ' checked="checked"';
											$replace_val[$rkey] .= '<label><input type="radio" name="cftsearch[' . rawurlencode($key) . '][]" value="' . esc_attr(trim($values[0])) . '"' . $class . $checked . ' /> ';			
											if ( $valueLabel[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabel[0]));
											else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
											$replace_val[$rkey] .= '</label>';
										endif;
										break;
									case 'select':
										if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; 
										$values = explode( '#', $rval['value'] );
										$valueLabel = isset($rval['valueLabel']) ? explode( '#', $rval['valueLabel'] ) : array();
										$default = isset($rval['default']) ? explode( '#', $rval['default'] ) : array();
										$selectLabel= isset($rval['selectLabel']) ? $rval['selectLabel'] : '';

										if ( isset($rval['searchCode']) && is_numeric($rval['searchCode']) ) :
											eval(stripcslashes($options['php'][$rval['searchCode']]));
										endif;
										$replace_val[$rkey] .= '<select name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]"' . $class . '>';
										$replace_val[$rkey] .= '<option value="">'.$selectLabel.'</option>';
										$j=0;
										foreach ( $values as $metaval ) :
											$metaval = trim($metaval);
											if ( in_array($metaval, $default) && !isset($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) )
													$checked = ' checked="checked"';

											if ( isset($_REQUEST['cftsearch']) && $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == $metaval ) $selected = ' selected="selected"';
											else $selected = "";
											$replace_val[$rkey] .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>';			
											if ( isset($valueLabel[$j]) )
												$replace_val[$rkey] .= stripcslashes(trim($valueLabel[$j]));
											else
												$replace_val[$rkey] .= stripcslashes($metaval);
											$replace_val[$rkey] .= '</option>' . "\n";
											$j++;
										endforeach;
										$replace_val[$rkey] .= '</select>' . "\n";
										break;
								endswitch;			
							endforeach;
						
							if ( isset($options['shortcode_format_use_php'][$format]) )
								$output = $this->EvalBuffer($output);
							$key = preg_quote($key, '/');
							$output = preg_replace('/\['.$key.'\](?!\[[0-9]+\])/', $replace_val[0], $output);
							$this->replace_val = $replace_val;
							$output = preg_replace_callback('/\['.$key.'\]\[([0-9]+)\](?!\[\])/', array($this, 'search_custom_field_values_callback'), $output);
						endforeach;
					endforeach;
				endfor;
			endif;

			if ( $button === true )
				$output .= '<p><input type="submit" value="' . $search_label . '" class="cftsearch_submit" /></p>' . "\n";
			$output .= '<input type="hidden" name="cftsearch_submit" value="1" />' . "\n";
			$output .= '</form>' . "\n";
		else :
			$fields = $this->get_custom_fields( $template );
	
			if ( $fields == null )
				return;

			$output = '<form method="get" action="'.get_option('home').'/" id="cftsearch'.(int)$format.'">' . "\n";
			foreach( $fields as $field_key => $field_val) :
				foreach( $field_val as $key => $val) :
					if ( isset($val['search']) && $val['search'] == true ) :
						if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) )
							$label = stripcslashes($val['label']);
						else $label = $key;
						$output .= '<dl>' ."\n";
						if ( !isset($val['hideKey']) || $val['hideKey'] != true) :
							$output .= '<dt><label>' . $label . '</label></dt>' ."\n";
						endif;

						$class = "";
						switch ( $val['type'] ) :
							case 'text':
							case 'textfield':
							case 'textarea':
								if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; 
								$output .= '<dd><input type="text" name="cftsearch[' . rawurlencode($key) . '][' . $key . '][]" value="' . (isset($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) ? esc_attr($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) : '') . '"' . $class . ' /></dd>';
								break;		
							case 'checkbox':
								$checked = '';
								if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"';
								if ( isset($_REQUEST['cftsearch'][rawurlencode($key)]) && is_array($_REQUEST['cftsearch'][rawurlencode($key)]) ) 
									foreach ( $_REQUEST['cftsearch'][rawurlencode($key)] as $values )
										if ( $val['value'] == $values[0] ) $checked = ' checked="checked"';
								$output .= '<dd><label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $key . '][]" value="' . esc_attr($val['value']) . '"' . $class . $checked . ' /> ';
								if ( !empty($val['valueLabel']) )
									$output .= stripcslashes($val['valueLabel']);
								else
									$output .= stripcslashes($val['value']);
								$output .= '</label></dd>' . "\n";
								break;
							case 'radio':
								if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; 
								$values = explode( '#', $val['value'] );
								$valueLabel = isset($val['valueLabel']) ? explode( '#', $val['valueLabel'] ) : '';
								$i=0;
								foreach ( $values as $metaval ) :
									$checked = '';
									$metaval = trim($metaval);
									if ( isset($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) && $_REQUEST['cftsearch'][rawurlencode($key)][0][0] == $metaval ) $checked = 'checked="checked"';
									$output .= '<dd><label>' . '<input type="radio" name="cftsearch[' . rawurlencode($key) . '][' . $key . '][]" value="' . esc_attr($metaval) . '"' . $class . $checked . ' /> ';			
									if ( !empty($val['valueLabel']) )
										$output .= stripcslashes(trim($valueLabel[$i]));
									else
										$output .= stripcslashes($metaval);
									$i++;
									$output .= '</label></dd>' . "\n";
								endforeach;
								break;
							case 'select':
								if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; 
								$values = explode( '#', $val['value'] );
								$valueLabel = isset($val['valueLabel']) ? explode( '#', $val['valueLabel'] ) : '';
								$output .= '<dd><select name="cftsearch[' . rawurlencode($key) . '][' . $key . '][]"' . $class . '>';
								$output .= '<option value=""></option>';
								$i=0;
								foreach ( $values as $metaval ) :
									$selected = '';
									$metaval = trim($metaval);
									if ( isset($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) && $_REQUEST['cftsearch'][rawurlencode($key)][0][0] == $metaval ) $selected = 'selected="selected"';
									else $selected = "";
									$output .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>';			
									if ( !empty($val['valueLabel']) )
										$output .= stripcslashes(trim($valueLabel[$i]));
									else
										$output .= stripcslashes($metaval);
									$output .= '</option>' . "\n";
									$i++;
								endforeach;
								$output .= '</select></dd>' . "\n";
								break;
						endswitch;
						$output .= '</dl>' ."\n";
					endif;
				endforeach;
			endforeach;
			if ( $button == true )
				$output .= '<p><input type="submit" value="' . $search_label . '" class="cftsearch_submit" /></p>' . "\n";
			$output .= '<input type="hidden" name="cftsearch_submit" value="1" /></p>' . "\n";
			$output .= '</form>' . "\n";
		endif;
		
		return do_shortcode(stripcslashes($output));
	}

Code file location:

custom-field-template/custom-field-template/custom-field-template.php

Conclusion

Now that you’ve learned how to embed the Custom Field Template Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *