• Resolved wpquestions2018

    (@wpquestions2018)


    Hi Greg,

    How can i limit the characters typed in location and title field, my users are abusing the freedom to have unlimited characters

    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,
    you can do that either using Custom FIelds add-on https://wpadverts.com/extensions/custom-fields/ or by adding the code below to your theme functions.php file

    
    add_filter( "adverts_form_load", "limit_title_and_location_length" );
    function limit_title_and_location_length( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
      foreach( $form["field"] as $key => $field ) {
        if( $field["name"] == "post_title" ) {
            $form["field"][$key]["validator"][] = array(
                "name" => "string_length",
                "params" => array( "min" => 5, "max" => 100 )
            );
        }
        if( $field["name"] == "adverts_location" ) {
            $form["field"][$key]["validator"][] = array(
                "name" => "string_length",
                "params" => array( "min" => 5, "max" => 100 )
            );
        }
      }
      return $form;
    }
    

    Just change the min and max values.

    Thread Starter wpquestions2018

    (@wpquestions2018)

    Hi Greg,

    I changed and a user can still type all characters they want and get displayed,

    the code is not working

    Thread Starter wpquestions2018

    (@wpquestions2018)

    Its working Greg, thanks good job.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limit characters’ is closed to new replies.