Created
July 20, 2014 01:49
-
-
Save yojance/3d7ce4f884049df279ec to your computer and use it in GitHub Desktop.
OptionTree Category Select Option Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OptionTree Category 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_category_select', | |
'label' => __( 'Category Select', 'text-domain' ), | |
'desc' => __( 'Your description', 'text-domain' ), | |
'type' => 'category-select', | |
'section' => 'your_section', | |
) | |
// Get the ID value saved on Theme Options Page | |
$spyr_demo_category_select = ot_get_option( 'spyr_demo_category_select' ); | |
// Get the ID value saved for a Page, Post or CPT ( Within the loop ) | |
$spyr_demo_category_select = get_post_meta( $post->ID, 'spyr_demo_category_select', true ); | |
// Get the Category name | |
$name = get_the_category_by_ID( $spyr_demo_category_select ); | |
// Get the category description | |
$cat_desc = category_description( $spyr_demo_category_select ); | |
// Get the Archive link for this category | |
$link = get_category_link( $spyr_demo_category_select ); | |
// Hide categories with zero posts from the drop down list | |
add_filter( 'ot_type_category_select_query', 'spyr_ot_type_category_select_hide_cats', 10, 2 ); | |
function spyr_ot_type_category_select_hide_cats( $query, $field_id ) { | |
if( 'demo_category_select' == $field_id ) { | |
return array_merge( $query, array( 'hide_empty' => true ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment