Title: Category Problem
Last modified: October 2, 2021

---

# Category Problem

 *  Resolved [pmmungai86](https://wordpress.org/support/users/pmmungai86/)
 * (@pmmungai86)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/category-problem-35/)
 * Automatically category selects the first option as shown in the screenshot, how
   can I have it blank and force users to fill it, if a user isn’t keen the first
   item in the category becomes their default category which is always not correct.
 * [https://postimg.cc/sGgscptW](https://postimg.cc/sGgscptW)
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcategory-problem-35%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/category-problem-35/#post-14934368)
 * Hi,
    if you have the Custom Fields extension [https://wpadverts.com/extensions/custom-fields/](https://wpadverts.com/extensions/custom-fields/)
   then while editing a Category field you should have there an option to show an
   empty option at the beginning of the list.
 * If you do not have this extension then you can insert the empty option using 
   the adverts_form_load filter
 *     ```
       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]["empty_option_text"] = "Select category ...";
               $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;
       }
       ```
   
 * The above code you can add in your theme functions.php file or even better create
   a new blank plugin ([https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/](https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/))
   and paste the code there.
 *  Thread Starter [pmmungai86](https://wordpress.org/support/users/pmmungai86/)
 * (@pmmungai86)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/category-problem-35/#post-14950042)
 * Where do I find this, ive checked everywhere and cant find this option
 * “while editing a Category field you should have there an option to show an empty
   option at the beginning of the list.”
 *  Thread Starter [pmmungai86](https://wordpress.org/support/users/pmmungai86/)
 * (@pmmungai86)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/category-problem-35/#post-14950071)
 * Works perfectly 🙂
 * Thanks Greg

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

The topic ‘Category Problem’ 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/)

 * 3 replies
 * 2 participants
 * Last reply from: [pmmungai86](https://wordpress.org/support/users/pmmungai86/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/category-problem-35/#post-14950071)
 * Status: resolved