• Resolved bojan1

    (@bojan1)


    Hello,

    is it possible to make that user is able to select only one category for ad when publishing new ad?
    Also is it possible to make category mandatory field?

    Best regards,
    Bojan

    https://unajmite.ga

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

    (@gwin)

    Hi,
    you can do both by adding the code below to your theme functions.php file

    
    add_filter( "adverts_form_load", "customize_adverts_add" );
    function customize_adverts_add( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
      foreach( $form["field"] as $key => $field ) {
        if( $field["name"] == "advert_category" ) {
            $form["field"][$key]["max_choices"] = 1;
            $form["field"][$key]["validator"] = array( "name"=> "is_required" );
        }
      }
      return $form;
    }
    
    Thread Starter bojan1

    (@bojan1)

    Thank you!

    Good morning, GREG.

    That did not work for me.

    Give an error in the plugin functions.php line 513 wpadverts.

    This functionality interests me a lot.

    Welcome to work again.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, please paste here the error you see after adding the code?

    Good afternoon
    Error returning by putting in the theme’s function.php file.
    Warning: Illegal string offset ‘name’ in C: \ xampp \ htdocs \ otherroutes \ wp-content \ plugins \ wpadverts \ includes \ functions.php on line 517

    Error returning by putting in plugin function file
    Category
    Warning: Illegal string offset ‘name’ in C: \ xampp \ htdocs \ otherroutes \ wp-content \ plugins \ wpadverts \ includes \ functions.php on line 517

    Remembering that I am using custom fields

    Plugin Author Greg Winiarski

    (@gwin)

    Try changing the line

    
    $form["field"][$key]["validator"] = array( "name"=> "is_required" );
    

    to

    
    $form["field"][$key]["validator"][] = array( "name"=> "is_required" );
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Advertisement categorie as mandatory field + limit category chosing to one’ is closed to new replies.