Skip to content

Instantly share code, notes, and snippets.

@yojance
Created July 20, 2014 01:50
Show Gist options
  • Save yojance/744bcc8047b2311a32c4 to your computer and use it in GitHub Desktop.
Save yojance/744bcc8047b2311a32c4 to your computer and use it in GitHub Desktop.
OptionTree Taxonomy Select Option Type
// OptionTree Taxonomy Select Option Type
// Example code when being used as a Metabox or
// Exported OptionTree file to be used in Theme Mode
array(
'id' => 'spyr_demo_taxonomy_select',
'label' => __( 'Taxonomy Select', 'text-domain' ),
'desc' => __( 'Your description', 'text-domain' ),
'type' => 'taxonomy-select',
'section' => 'your_section',
'taxonomy' => 'category,post_tag', // Defaults to Categories and Tags
)
// Get the ID value saved on Theme Options Page
$spyr_demo_taxonomy_select = ot_get_option( 'spyr_demo_taxonomy_select' );
// Get the ID value saved for a Page, Post or CPT ( Within the loop )
$spyr_demo_taxonomy_select = get_post_meta( $post->ID, 'spyr_demo_taxonomy_select', true );
// Override Taxonomy via code
add_filter( 'ot_type_taxonomy_select_query', 'spyr_ot_type_taxonomy_select_set_tax', 10, 2 );
function spyr_ot_type_taxonomy_select_set_tax( $query, $field_id ) {
if( 'spyr_demo_taxonomy_select' == $field_id ) {
return array_merge( $query, array( 'taxonomy' => array( 'genre' ) ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment