• Resolved pmmungai86

    (@pmmungai86)


    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

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    if you have the Custom Fields extension 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/) and paste the code there.

    Thread Starter pmmungai86

    (@pmmungai86)

    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

    (@pmmungai86)

    Works perfectly 🙂

    Thanks Greg

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

The topic ‘Category Problem’ is closed to new replies.