Adding Fields Using PHP

Adding fields this way is the best way to do it if you are working in multiple server environments, for example if you have both a test server and a production server.

If you want to add fields using GUI that is also possible, but moving fields from one server to another may be a bit cumbersome then, involving database exports and imports.

Example

This example adds a lot of fields to a field group and then makes that field group available to all posts, and finally it makes this the field group the default one for all posts.

14 thoughts on “Adding Fields Using PHP

  1. acy

    Just to make sure… How is this working? When I use this in functions.php is creates a new field group every time I reload the page… Where should it go instead?

  2. nicolas

    how to update dropdown values? exists api function to do it? For example, i need to update dropdown vaules without using GUI (maybe by code in frontend), thanks

      1. Jo

        array(
        ‘slug’ => “my_radiobutton_field_slug”,
        ‘name’ => ‘Test radiobutton’,
        ‘description’ => ‘Radiobutton description’,
        ‘type’ => ‘radiobutton’,
        ‘type_radiobutton_options’ => array(
        array(“value” => “Yes”),
        array(“value” => “No”)
        )
        ),

        This one (example above) doesn’t work for me. nothing appears.

        modification of mine:

        array(
        ‘slug’ => “my_radiobutton_field_slug”,
        ‘name’ => ‘Test radiobutton’,
        ‘description’ => ‘Radiobutton description’,
        ‘type’ => ‘radiobuttons’,
        ‘type_radiobuttons_options’ => array(
        array(“value” => “Yes”),
        array(“value” => “No”)
        )
        ),

        With those one, it appears but there is a bug.

  3. gagarine

    In fact this example doesn’t fully works. Mainly simple_fields_register_post_connector do not make the group a default group for the content type. Their are also absolutely no documentation for simple_fields_register_post_connector….

Leave a Reply