Category pie diagram meta box in post editing page

I am trying to build a plugin for showing a pie diagram based on the number of those categories which have maximum posts. This diagram is a meta box in post editing page. Here is my source of inspiration: jquery charts

Most of the way the function works is same but I added some hooks to add it into meta box.
Here is my code:

Read More
add_action( 'add_meta_boxes', 'category_meta_box_add' );

function category_meta_box_add() {  
add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'categories', 'post', 'normal', 'high' ); }  

function categories($atts,$content = '') { }        //full function is defined in link above
add_shortcode('mycategories', 'categories');
echo do_shortcode('[mycategories]');

This plugin on installing shows meta box without data, also gives error:

The plugin generated 721 characters of unexpected output during
activation. If you notice “headers already sent” messages, problems
with syndication feeds or other issues, try deactivating or removing
this plugin.

How to resolve this?

Thanks

Full plugin here

Related posts

Leave a Reply

1 comment

  1. The problem might be because of this line:

    echo do_shortcode('[mycategories]');
    

    It should not stand alone like this in the plugin file, because this will show up before the headers are sent out. I guess you added this line just to check the output? Try to remove this line or encapsulate it with a relevant function. You could instead add the shortcode [mycategories] into the content of some post/page to test it.

    You could replace this line

    add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'categories', 'post', 'normal', 'high' );  
    

    with

    add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'category_meta_box_html', 'post', 'normal', 'high' );  
    

    and add this function:

    function category_meta_box_html(){
        echo do_shortcode("[mycategories]");
    }
    

    to display the graph inside the metabox.