• Resolved Nishant Patel

    (@nishantpatel121)


    Hello, As we added advert category add on and Created as hierarchical categories.

    we want user to select only one check box not all of them applied to

    Thanks

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

    (@gwin)

    Hi,
    you can do that either with the Custom Fields extension or by adding the code below in your theme functions.php file (or even better by creating a new blank plugin and pasting the code there https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/).

    
    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 Nishant Patel

    (@nishantpatel121)

    Thank you so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Select Only one category on Form’ is closed to new replies.