Wordpress taxonomy convert checkbox to radio buttons


I need to convert post type’s category sections checkbox to radio buttons..

So i have search for it and i got replay from below link and also its function added in this page..

http://wordpress.stackexchange.com/questions/139269/wordpress-taxonomy-radio-buttons


function wpse_139269_term_radio_checklist($args) {
if (!empty($args['taxonomy']) && $args['taxonomy'] === 'service' /* <== Change to your required taxonomy */) {
if (empty($args['walker']) || is_a($args['walker'], 'Walker')) { // Don't override 3rd party walkers.
if (!class_exists('WPSE_139269_Walker_Category_Radio_Checklist')) {

/**
* Custom walker for switching checkbox inputs to radio.
*
* @see Walker_Category_Checklist
*/
class WPSE_139269_Walker_Category_Radio_Checklist extends Walker_Category_Checklist {

function walk($elements, $max_depth, $args = array()) {
$output = parent::walk($elements, $max_depth, $args);
$output = str_replace(
array('type="checkbox"', "type='checkbox'"), array('type="radio"', "type='radio'"), $output
);

return $output;
}

}

}

$args['walker'] = new WPSE_139269_Walker_Category_Radio_Checklist;
}
}

return $args;
}

add_filter('wp_terms_checklist_args', 'wpse_139269_term_radio_checklist');

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s