1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Locations
  5. Taxonomy Options

Taxonomy Options

The WordPress Studio Framework (WPSF) can also be used to create additional fields on WordPress taxonomies.

Arguments

NameTypeDefaultDescription
taxonomyarray|string Provice any number of taxonomy slugs for a given “term” box to appear
data_typestringserializeDatabase save option type (serialize | unserialize)
defaultsarray Sets all default values from an external array (optional)
classstring Extra CSS classes (space separated) to append to the main framework

Taxonomy Options Framework Example

// Check to see if WordPress Studio Framework is loaded
if ( class_exists( 'WPSF' )){
  //Set unique ID
  $prefix = 'custom_tax_options';

  //Create taxonomy options
  WPSF::createTaxonomyOptions( $prefix, array(
    'taxonomy' => 'category',
    'data_type' => 'serialize',
  ));

  //Create a section
  WPSF::createSection( $prefix, array(
    'fields' => array(
      array(
        'id' => 'example-text',
        'type' => 'text',
        'title' => 'Example Text',
      ),
      array(
        'id' => 'example-textarea',
        'type' => 'textarea',
        'title' => 'Example Textarea',
    )
  ));
}

Extract Option (data_type => serialize)

$term = get_category_by_slug( 'uncategorized' );
$meta = get_term_meta( $term->term_id, 'custom_tax_options', true );

echo $meta['example-text'];
echo $meta['example-textarea'];

Extract Option (data_type => unserialize)

$term = get_category_by_slug( 'uncategorized' );
echo get_term_meta( $term->term_id, 'example-text', true );
echo get_term_meta( $term->term_id, 'example-text', true );
Was this article helpful to you? Yes No

How can we help?