I was looking for a plugin for this, but so far I cant find one that does what I want. I limited the user role capabilities with 'Restrict Capabilities'. But the authors still have to click the category when writing a post. For it to be idiot proof I'd like to have the right category be the default (even if it's the only category they can see).

Is there a piece of code I can insert in functions.php to assign each user role to the right category?

Appreciate any help I can get! Thanks.


This may be similar to what you are looking for, it doesn't force a category, but doesn't let the user submit the new post unless at least one category is selected

This solution requires jQuery, but with little modification can be ported to plain JavaScript

//intercept the "update" or "publish" button
    //grab the GET query (just to be sure we are editing a post, not a page)   
    var split = location.search.replace('?', '').split('&').map(function(val){
        return val.split('=');

    //check GET value for "post" and "edit" variables
    if(split[0][0] == 'post' && split[1][0] == 'action' && split[1][1] == 'edit' ){

        //get the category checkboxes
        var categories = $('input[name=post_category\\[\\]]');

        //flag to check if at least one category is selected
        var atLeastOneChecked = false;

        //iterate over the category checkboxes
        for (var i = 0; i < categories.length; i++) {

            //if we find one selected and is not the 0 cat let return true and have 
            //the form submitted
            if(categories[i].checked == true && !(categories[i].value == 0)){
                return true;

        //else, let your users know they must select a category
        alert("You Must Select at least one of your visible categories");
        return false;
    return true;

Well it's hard to tell what you're talking about without context, but it kind of sounds like you just want to have new posts assigned to a particular category by default?

If that is true, then just go to Settings >> Writing and change the "Default Post Category" to whatever category you want selected when you create a new post.

If that's not what you want to do, then I think we need some more context, and a better description of what you want to do please.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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