php - How to pass category from custom post type in listbox tinyMCE 4 -
bellow code pass category wordpress default post in tinymce 4. have done properly.
function list_categories( $cat_id, &$output = array() ) { $categories = get_categories( 'hide_empty=0&orderby=name&order=asc& parent=' . $cat_id ); foreach( $categories $cat ) { $output[] = array( 'text' => $cat->name, 'value' => $cat->term_id ); list_categories( $cat->term_id, $output ); } return $output; } $list = list_categories(0); // array of categories p_localize_script( 'some_handle', 'mce_options', array( 'categories' => json_encode( list_categories(0) ) ) ); add_action( 'admin_enqueue_scripts', 'mce_admin_scripts' ); function mce_admin_scripts( $hook ) { if ( $hook == 'post.php' || $hook == 'post-new.php' ) { add_action( "admin_head-$hook", 'mce_admin_head' ); } } function mce_admin_head() { echo '<script type="text/javascript">var mce_options=' . json_encode( array( 'categories' => list_categories(0) ) ) . '; </script>'; } { type: 'listbox', name: 'sdscategory', label: 'category', 'values': mce_options.categories }
but question i need pass custom category custom post in tinemce 4. creating custom post type 'bxcarousel' & custom category 'bx_carousel_cata'. not expert in php please me
Comments
Post a Comment