/Taxonomy_Single_Term

This library helps you remove and replace the built-in taxonomy metabox with a radio or select metabox. http://webdevstudios.com/2013/07/08/replace-wordpress-default-taxonomy-metabox-with-a-radio-select-metabox/

Primary LanguagePHP

Taxonomy_Single_Term

Version: 0.2.4

Taxonomies in WordPress are super powerful. The purpose of taxonomies is to create relationships among post types. Unfortunately the UI doesn't effectively enforce limiting to a single term.

This library helps you remove and replace the built-in taxonomy metabox with a radio or select metabox.

Read more: How To: Replace WordPress Default Taxonomy Metabox with a Radio Select Metabox

WebDevStudios. WordPress for big brands.

Usage

  1. Include the class.taxonomy-single-term.php file from within your plugin or theme
  2. Initialize the class (update the taxonomy slug with your own): $custom_tax_mb = new Taxonomy_Single_Term( 'custom-tax-slug' );

Optional

    • Second parameter is an array of post_types,
    • The third parameter is either 'radio', or 'select' (defaulting to radio). To use a select type on the foo post_type: $custom_tax_mb = new Taxonomy_Single_Term( 'custom-tax-slug', array( 'foo' ), 'select' );
    • The fourth parameter is the default to select for posts that have not had the taxonomy set. This defaults to the system default option where available and falls back to none where not.
  1. Update optional class properties like:
// Priority of the metabox placement.
$custom_tax_mb->set( 'priority', 'low' );

// 'normal' to move it under the post content.
$custom_tax_mb->set( 'context', 'normal' );

// Custom title for your metabox
$custom_tax_mb->set( 'metabox_title', __( 'Custom Metabox Title', 'yourtheme' ) );

// Makes a selection required.
$custom_tax_mb->set( 'force_selection', true );

// Will keep radio elements from indenting for child-terms.
$custom_tax_mb->set( 'indented', false );

// Allows adding of new terms from the metabox
$custom_tax_mb->set( 'allow_new_terms', true );

// set default
$custom_tax_mb->set( 'default', 'default-slug' ); // or
$custom_tax_mb->set( 'default', 'Default Name' ); // or
$custom_tax_mb->set( 'default', 123 ); // default term_id

Change Log

0.2.4

  • Make Taxonomy_Single_Term::term_fields_list() more versatile.
  • Escape attributes. Props @rnaby, #25.
  • Fix some issues with the selected functionality. See #24.

0.2.3

  • Add hooks to the metabox, taxonomy_single_term_metabox_bottom and taxonomy_single_term_metabox_top.

0.2.2

0.2.1

  • Add setter method. Props @JustinSainton
  • Add getter magic method for retrieving properties

0.2.0

  • Ability to choose Select elements vs Radios. Props @jchristopher
  • Rename plugin. Props @jchristopher
  • Optional allow_new_terms parameter to include a new-term add button in the metabox. Props @jchristopher

0.1.4

  • Bulk editing now works as expected. A singular term will be saved against the post.

0.1.3

  • Adds footer JS on post listing pages that transforms quick-edit inputs to radios.