0

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?

explanation image

1
  • 1
    Please, add more details to the Question, it's hard to get what you mean. Use screenshots if necessary.
    – brasofilo
    May 15, 2013 at 7:23

2 Answers 2

0

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

0

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.