Title: category_save_pre
Last modified: August 19, 2016

---

# category_save_pre

 *  [crille](https://wordpress.org/support/users/crille/)
 * (@crille)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/category_save_pre/)
 * Hello!
 * I have a problem with my first plugin, because I don’t know, how the category_save_pre
   filter works.
 * The plugin should automatically select the category, if there is only one category.
   I know, there’s a setting for default_category, but I use another plugin, which
   exclude for certain users the default_category.
 *     ```
       function chooseCategory($id)
       {
       	$cat = get_categories(array('hide_empty'=>FALSE));
       	if (count($cat) == 1)
       	{
       		$id = $cat[0]->cat_ID;
       	}
       	return $id;
       }
       add_filter('category_save_pre', 'chooseCategory');
       ```
   
 * What kind of parameters do I get for chooseCategory and what should be returned
   by this function?
 * Thanks
    crille

The topic ‘category_save_pre’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [crille](https://wordpress.org/support/users/crille/)
 * Last activity: [17 years, 11 months ago](https://wordpress.org/support/topic/category_save_pre/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
