The WordPress Studio Framework (WPSF) can also be used to create additional fields on WordPress taxonomies.
Arguments
Name | Type | Default | Description |
---|---|---|---|
taxonomy | array|string | Provice any number of taxonomy slugs for a given “term” box to appear | |
data_type | string | serialize | Database save option type (serialize | unserialize) |
defaults | array | Sets all default values from an external array (optional) | |
class | string | 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 );