Title: Change default category
Last modified: June 15, 2018

---

# Change default category

 *  Resolved [wpusrnm](https://wordpress.org/support/users/wpusrnm/)
 * (@wpusrnm)
 * [8 years ago](https://wordpress.org/support/topic/change-default-category-4/)
 * Hi, now when user is posting an add, there is default category selected and i
   want to force the user to select it just to avoid posts in the wrong category.
   How I achieve that?
    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [8 years ago](https://wordpress.org/support/topic/change-default-category-4/#post-10409976)
 * Hi,
    you can set default value for advert_category field by adding the code below
   in your theme functions.php file
 *     ```
       add_action( "adverts_form_bind", "default_value_for_adverts_add", 10, 2 );
       function default_value_for_adverts_add( $form, $data ) {
           if( ! isset( $data['advert_category'] ) ) {
               $form->set_value( "advert_category", 25 );
           }
           return $form;
       }
       ```
   
 * Just replace 25 with actual ID (numeric) of the taxonomy you would like to use
   as a default.
 *  Thread Starter [wpusrnm](https://wordpress.org/support/users/wpusrnm/)
 * (@wpusrnm)
 * [8 years ago](https://wordpress.org/support/topic/change-default-category-4/#post-10410927)
 * ok, I see I wasn’t clear; my bad.
    anyway, what I want to achieve is to set the
   categpry to none and not leave the user to post advert until he sellect a category.
    -  This reply was modified 8 years ago by [wpusrnm](https://wordpress.org/support/users/wpusrnm/).
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [8 years ago](https://wordpress.org/support/topic/change-default-category-4/#post-10413430)
 * Ohh ok, in this case you will need to use a different code
 *     ```
       add_filter( "adverts_form_load", "single_select_advert_category" );
       function single_select_advert_category( $form ) {
         if( $form['name'] != "advert" ) {
           return $form;
         }
         foreach( $form["field"] as $key => $field ) {
           if( $field["name"] == "advert_category" ) {
               $form["field"][$key]["empty_option"] = true;
               $form["field"][$key]["max_choices"] = 1;
               $form["field"][$key]["validator"] = array();
               $form["field"][$key]["validator"][] = array( 
                   "name" => "max_choices",
                   "params" => array( "max_choices" => 1 )
               );
           }
         }
         return $form;
       }
       ```
   
 *  Thread Starter [wpusrnm](https://wordpress.org/support/users/wpusrnm/)
 * (@wpusrnm)
 * [8 years ago](https://wordpress.org/support/topic/change-default-category-4/#post-10414751)
 * thanks man, that solved it!
    just in case someone wants to implement it. you 
   must set the filter that makes the category required after this one. big thanks!!!
    -  This reply was modified 8 years ago by [wpusrnm](https://wordpress.org/support/users/wpusrnm/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Change default category’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

## Tags

 * [category.default](https://wordpress.org/support/topic-tag/category-default/)

 * 4 replies
 * 2 participants
 * Last reply from: [wpusrnm](https://wordpress.org/support/users/wpusrnm/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/change-default-category-4/#post-10414751)
 * Status: resolved