Skip to content

Group Fields Format

Chris Chasm edited this page May 27, 2019 · 5 revisions

Fields have different types. Each type will need it's own syntax. The list of fields will changed based on your install. For a list of available fields have a look at: Group Post Type page

Text

Field examples:

  • title
fields = [
  "title" => "John Doe's Awesome Group" 
]

key_select

Field examples:

  • group_status
  • group_type
  • is_church
  • church_baptism
  • church_bible
  • church_communion
  • church_fellowship
  • church_giving
  • church_prayer
  • church_praise
  • church_sharing
  • church_leaders
  • church_commitment

The options for each of these can be found in the Group Post Type page The key is used to set save the field instead of the value.

fields = [
   "group_status" => "active",
   "church_commitment" => "1"
]

multi_select

Field examples:

  • health_metrics
$fields = [
  "health_metrics" => [
    "values" => [ 
      [ "value" => "church_baptism" ],  //add new, or make sure it exists
      [ "value" => "church_bible", "delete" => true ] //remove existing
    ],
    "force_values" => false // true will set source to the values entries. removing all others
  ]
]

Contact Fields

  • contact_address

There are three actions you can take:

  • Create, if you don't include a key, a new field will be created
  • Update, include the key and value to update
  • Delete, including the key and the delete flag will remove the address
$fields = [
  "contact_address" => [
    ["value" => "123 Awesome street, Jesus town"], //create
    ["key" => "contact_address_123", "value" => "123 Awesome street, Jesus town"],  //update
    ["key" => "contact_address_123", "delete" => true] //delete
  ] 
]

To change a detail on a contact method:

$fields = [
  "contact_address" => [
    ["key" => "contact_address_123", "verified" => true],  //update verified flag
  ]
]

Date

  • start_date
  • end_date
$fields = [
  "start_date" => "2018-12-31" //format yyyy-mm-dd
]

user_select

  • assigned_to //int, a user id
$fields = [
   "assigned_to" => 4  //the id of the user
]

Number

  • (no number field implemented currently)
$fields = [
  "cool number field" => 3
]

Connections

  • locations
  • parent_groups
  • child_groups
  • people_groups
  • members

Let's say our group is connected to locations with IDs 1, 3 and 43. This example will add the location with ID 1 and will remove the location with ID 43. The group will then be connected to locations 1 and 3

$fields = [
  "locations" => [
    "values" => [ 
      [ "value" => 1 ],
      [ "value" => 43, "delete" => true ]
    ],
    "force_values" => false // true will set locations to the values entries. removing all others
  ]
]

This example will remove locations 1 and 3 and leave the group connected to location 5:

$fields = [
  "locations" => [
    "values" => [ 
      [ "value" => 5 ],
    ],
    "force_values" => true // true will set locations to the values entries. removing all others
  ]
]

Fields example together

$fields = [
  "title" => "Bob",
  "group_status" => "active",
  "contact_address" => [
    ["value" => "123 Awesome street, Jesus town"],
  ],
  "locations" => [ 
    "values" => [
      [ "value" => "9" ]
    ]
  ],
  "start_date" => "2017-11-34",
]
Disciple_Tools_Groups::create_group( $fields, true )

JavaScript example with REST

jQuery.ajax({
  type: "POST",
  data: JSON.stringify({
    title:"bob", 
    contact_address:[{value:"123 Awesome street, Jesus town"}]
  }),
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  url: wpApiSettings.root + `dt/v1/group/create`,
  beforeSend: function(xhr) {
    xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);
  }