Create 3 buttons for new post for a different category

I am customizing the admin panel of WordPress. I have users with roles to only write to 3 categories. I would like to design 3 buttons or divs to create a new post but each one for a different category. That in the dashboard.

I will have a different dashboard for role user

Any idea?

Topic dashboard Wordpress

Category Web


If you would use custom post types instead then you could use links like:

/wp-admin/post-new.php?post_type=news
/wp-admin/post-new.php?post_type=sport
/wp-admin/post-new.php?post_type=people

in your dashboard to take you to the corresponding new post page.

Update:

If you can't use custom post types and must use post categories, you can try to use a link like this one:

/wp-admin/index.php?mycat=20

by adding the following code into your functions.php file (or make a plugin with the code):

add_action( 'admin_head-index.php', 'my_post_preset_wpse_99518' );
function my_post_preset_wpse_99518() {
        global $current_user;
        $allowed_cat_ids = array(10,20); //EDIT  
        if(isset($_GET['mycat'])){
                $mycat = (int) $_GET['mycat']; 
                if(in_array($mycat, $allowed_cat_ids, TRUE)){
                        $newpost = array(
                                'post_title' => ' ', // the title must be non-empty
                                'post_status' => 'draft', 
                                'post_date' => date('Y-m-d H:i:s'), 
                                'post_author' => $current_user->ID, 
                                'post_category' => array($mycat), 
                        );
                        $newpostobj = get_post(wp_insert_post($newpost)); 
                        if($newpostobj)
                            wp_redirect(admin_url("post.php?action=edit&post={$newpostobj->ID}"));
                            exit();

                }
        }
}

where you edit this line to your needs:

        $allowed_cat_ids = array(10,20); //EDIT  

This will insert a new post with a preset category.


it's not possible since new post not set to category. except, you need to create new post first assigned with selected category.

so just create function that create new post on button click.

the problem is you will find many empty post if user play with that link

to create dashboard widget you can check offical docs wp_add_dashboard_widget

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.