posts - Set Default Category to Username

admin2025-01-08  4

I installed a plugin called "Symbiosis" which creates categories automatically copying a user's username upon them signing up.

Whenever any user creates a post on the site, I am trying to figure out how to assign that category that was already created with the new post.

I want to set WP Default Category to the authors username so that when anyone creates a post it automatically posts under their name. (my users do not have access to default wp-panels)

I know about the dropdown in the settings > writing panel but that's not what I'm looking for as I cannot customize the slug to a users username.

Is this possible via plugin or programatically somewhere else?

The categories are all already created. I can pull the loggedin users username and echo it but I'm not sure where to put it:

<?php global $current_user; if ( isset($current_user) ) {echo $current_user->user_login;}?>

I installed a plugin called "Symbiosis" which creates categories automatically copying a user's username upon them signing up.

Whenever any user creates a post on the site, I am trying to figure out how to assign that category that was already created with the new post.

I want to set WP Default Category to the authors username so that when anyone creates a post it automatically posts under their name. (my users do not have access to default wp-panels)

I know about the dropdown in the settings > writing panel but that's not what I'm looking for as I cannot customize the slug to a users username.

Is this possible via plugin or programatically somewhere else?

The categories are all already created. I can pull the loggedin users username and echo it but I'm not sure where to put it:

<?php global $current_user; if ( isset($current_user) ) {echo $current_user->user_login;}?>
Share Improve this question asked Mar 2, 2013 at 7:23 user1823055user1823055 431 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

The default category is stored in the options table under option named default_category , so you can do something like this:

add_action('admin_init','set_user_default_cat_wpa89057');
function set_user_default_cat_wpa89057(){
    global $current_user; 
    if ( isset($current_user) ) {
        update_option( 'default_category',  $current_user->user_login);
    }
}
function setcategory_2_username($id){
   global $current_user;  
   $category_id = get_cat_ID( $current_user->user_login );
   wp_set_post_categories( $post_id, array($category_id) );
}
add_action('save_post', 'setcategory_2_username');
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736268538a1282.html

最新回复(0)