I have created a custom post type for a property rental site created with WordPress. In it I want to have the input section as checkboxes:
and get the output like this:
I have created a custom post type for a property rental site created with WordPress. In it I want to have the input section as checkboxes:
and get the output like this:
Share Improve this question edited Dec 18, 2012 at 12:53 stealthyninja 1,1301 gold badge15 silver badges21 bronze badges asked Dec 18, 2012 at 11:32 irshadavirshadav 31 silver badge3 bronze badges 1- use this plugin and enjoy its features, your answer is in the first page of its website. :) Advanced Custom Fields – Saeed Alipoor Commented Dec 23, 2012 at 13:25
2 Answers
Reset to default 1You can do this by custom meta, all you have to do create custom metabox and the your checkboxes on it, the easiest way to create custom metabox is
1). Download WP Alchemy Metabox Class from here
2). Palce 'wpalchemy' folder inside of your theme folder
in your function.php file
include_once WP_CONTENT_DIR . '/themes/yourtheme/wpalchemy/MetaBox.php';
3). after that, create two php files by following names 'my-special-feature-meta.php' , 'my-special-feature-spec.php' (you can name your php files whatever you want).
in your 'my-special-feature-spec.php' file
<?php
global my_special_features;
$my_special_features = new WPAlchemy_MetaBox(array
(
'id' => '_my_special_features',
'title' => 'Special Features',
'template' => get_stylesheet_directory() . 'my-special-feature-meta.php',
'types' => array('page','post','your_custom_post')
));
/* eof */
and your 'my-special-feature-meta.php' file
Group checkbox test #1
<?php
global $my_special_features;
$items = array('internet', 'laundry', 'garage', 'tv');
?>
<?php while ($my_special_features->have_fields('cb_ex', count($items))): ?>
<?php $item = $items[$mb->get_the_index()]; ?>
<input type="checkbox" name="<?php $my_special_features ->the_name(); ?>" value="<?php echo $item; ?>"<?php $my_special_features ->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/>
<?php endwhile; ?>
okay you have created your checkbox lists in your custom post type, now you have to display the meta results on your front end, to do that, create php function in your functions.php file
function display_special_fetures(){
global $my_special_features;
$myresults = $my_special_features->the_meta();
if(!empty($myresults)){
foreach($myresults){
echo '<img src="'get_stylesheet_directory().'/'.$myresults['cb_ex'].'">';
}
}
}
finally place this function inside your loop or single.
You can use the following plugin: http://wordpress.org/extend/plugins/custom-field-suite/
After that, in your template file, just use plugin's API:
<?php if( $cfs->get('field_name') ): ?>
<img src="blank.gif" class="sprite icon" />
<?php endif; ?>
Plugin Documentation: http://uproot.us/projects/cfs/documentation/
Of course, you can use Wordpress built-in functionality, just add your custom field on post edit screen, then use get_post_meta() to get custom field value.