• Carin

    (@sparksfreebies)


    Hi Greg, First of all, I want to thank you for the outstanding support you give! I have already left a 5 star review but wish I could leave another one!

    My question is a bit complex, I have Predefined my Locations based on Local City Names, but need to also add an address field to the Help Wanted Form in order to comply with Job Posting Schema (requires an address field). I read the https://wpadverts.com/doc/custom-fields/ and reviewed default.php to see if there was an “address” field already defined, but all I found was “location” which I have already pre-defined. What I don’t know is if I will be able to assign these text fields in Schema to the address requirement, I think I will be able to, but wondered if you had any other suggestions I should know about before I try? Do you know if they are supposed to be grouped together somehow. I am also working with my developer, but he just got married, and so I am trying to get a head start here before he comes back to work!

    Should I create text fields with labels for Street Address (example only):

        $form["field"][] = array(            
            "name" => "my_street_field",
            "type" => "adverts_field_text",
            "order" => 25,
            "label" => "Street Address",
         
            )
        );
    , then also for City, State and Zipcode (Zipcode using "name" => "string_length",
                        "params" => array( "min" => 5)    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    thanks for the compliments :), the code you are using when saving an ad will create an entry in the wp_postmeta table with the meta_key = my_street_field and the meta_value you entered in the form.

    In other words, this will be a standard entry in the default WP table so the value will be visible to any plugin, that being said I cannot tell how this connects to a plugin generating Schemes.

    For the reference, the whole code for adding the my_street_field should look like this

    
    add_filter( "adverts_form_load", function( $form ) {
      if( $form["name"] != "advert" ) {
        return $form;
      }
      $form["field"][] = array(            
        "name" => "my_street_field",
        "type" => "adverts_field_text",
        "order" => 25,
        "label" => "Street Address",
        "validator" => array(
          array( "name" => "string_length", "params" => array( "min" => 5 ) )
        )
      );
      return $form;
    } );
    

    and ideally, you should have a blank plugin where you put all your snippets so they will not get overwritten on the update https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/

    Thread Starter Carin

    (@sparksfreebies)

    It worked great, but it does not appear in Custom Fields in my Form Schemes, I wanted to make it required in one Scheme and not required in another. Is that possible to have it show up in Custom Options Form Schemes?

    Plugin Author Greg Winiarski

    (@gwin)

    By default the adverts_form_load is run after the Custom Fields extension modified form, so in the Custom Fields editor do not see the fields that were added via the API (making it work the other way around would create a problem when saving the form that is the field would be saved in the form scheme but also added via the API).

    That being said if you are using the Custom Fields extension you can add the my_street_field field using the CF editor you do not need a code snippet to do that.

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

The topic ‘Registering Custom Field Address’ is closed to new replies.