Add a - before any of these options to return them in descending order
Example:
// get records assigned to me, ordered by creation date from newest to oldestlet searchParameters = { assigned_to: [ 'me' ], sort:`-post_date`}
user_select
Parameters: (array) of presets or ids.
me // records assigned to the user making the query
83 // records assigned to user of ID 83
-84 // exclude records assigned to user 84
Example:
// get records assigned to melet searchParameters = { assigned_to: [ 'me' ]}// get records assigned_to user 22 and user 48let searchParameters = { assigned_to: [ 22 ]}
key_select, multi_select, tags
Parameters: (array) of keys.
overall_stats (key_select)
milestones (mutli_select)
gender (key_select)
tags (tags)
etc
Example:
// get contacts that have the 'Has Bible' or 'Reading Bible' milestones and that are at the 'Meeting Scheduled' stage.let searchParameters = { milestones: [ 'milestone_has_bible','milestone_reading_bible' ], seeker_path: [ 'scheduled' ], tags: [ 'open' ]}
// get contacts that have the 'Has Bible' milestone but not the 'Reading Bible' milestone.let searchParameters = { milestones: [ 'milestone_has_bible','-milestone_reading_bible' ],}
connection
Parameters (array) of IDs
subassigned
groups
etc
Example:
// get contacts subassigned to contact 93. Exclude contacts subassigned to contact 23let searchParameters = { subassinged: [ 93,-23 ]}
Example:
// get contacts assigned_to user 22 **OR** subassigned to contact 93let searchParameters = { [ assigned_to => [ 22 ], subassinged: [ 93 ] ]}
Example:
// get contacts with no groups connectedlet searchParameters = { groups: [] }
Example:
// get all contact with any connected grouplet searchParameters = { groups: [*] }
location
Parameters: (array) of location_grid IDs
location_grid
Example:
// get contacts in location with location_grid (in the dt_location_grid table grid_id) id 123456// but exclude location 5678let searchParameters = { location_grid: [ 123456,-5678 ]}
date
Parameters: start and end
created_on // date the record was created
baptism_date
etc
Example:
// get the records created between in 2018let searchParameters = { created_on : { start:"2018-01-01", end:"2019-01-01" }}// get contacts baptized before Feb 2019let searchParameters = { baptism_date : { end:"2019-02-01" }}
boolean
Parameters (array). "1" for true, "0" for false
requires_update
etc
Example:
// get records that need an updatelet searchParameters = { requires_update: [ "1" ]}
number
Parameters (array):
operator options: <, >, <=, >= or =
number
Field examples:
baptism_generations
quick actions
Example:
// get records that are baptism generation greater than 4let searchParameters = { baptism_generation => [ "operator"=>">","number"=>4 ],}
textcommunication_channel
Parameters: (array) or text to search for.
contact_phone
name
nickname
etc
Examples:
// search phone numbers matching 123 anywhere in the numberlet searchParameters = { contact_phone: ["123"]}// search phone numbers matching 123 exactlylet searchParameters = { contact_phone: ["^123"]}// search records for names; which do not match "Bob"let searchParameters = { name: ["-Bob"]}// search phone numbers matching 123 but don't match 234let searchParameters = { contact_phone: ["123","-234"]}// search records for any phone numberlet searchParameters = { contact_phone: ["*"]}// search for records with no phone numberslet searchParameters = { contact_phone: []}
Record Text dynamic Search
text (string).
fields_to_search (array). Default is ["name", "comms"].
fields_to_search options:
all
comment
name
text_field_key // any text field key
comms //communication channels
Example:
// search for "Bob" in name and communication channel fieldslet searchParameters = { text:"Bob"}// search across all fieldslet searchParameters = { text:"Bob", fields_to_search: ["all"],//search all fields in the listed options}// search specific field for any text field like "nickname"let searchParameters = { text:"Bob", fields_to_search: ["nickname"]}// search multiple fields for given text querylet searchParameters = { text:"Bob", fields_to_search: ["nickname","name"]}// search for "Bob" in commentslet searchParameters = { text:"Bob", fields_to_search: ["comment"]}
Combining with AND/OR logic
Wrapping parameters in arrays with switch add AND/OR logic. The first level of values has AND logic. Wrapping them in an array gives them an OR logic. 1st layer: AND 2nd layer: OR 3rd layer: AND etc
Note that the query is sent in the fields array and thath the structure is a bit different.
Examples:
// records that are of field `type` `personal` AND coached by melet searchParameters = { fields: [ { type: ["personal"], },// AND { coached_by: [ "me" ] } ], sort:"name"}
// records that are of type "personal" OR coached by melet searchParameters = { fields: [ { type: ["personal"],//OR coached_by: [ "me" ] } ], sort:"name"}
// records that are ( ( type "personal" AND coached_by me ) OR ( assigned to me and active ) ) AND shared with melet searchParameters = { fields: [ [ { type: ["personal"],// AND coached_by: [ "me" ] },// OR { assigned_to: [ "me" ],//AND overall_status: [ "active" ] } ],//AND { shared_with: [ "me" ] }}
Recently viewed posts
dt_recent (bool) true. Cannot be combined with other parameters except: fields_to_return
Example:
//Get the 30 most recently viewed posts by the user making the request.let searchParameters = { dt_recent:true}
Paging Parameters
offset (integer) the number of records to skip. Optional. limit (integer) the number of records to include in the response. Default is 100, Maximum: 1000. Warning: a large number may cause a server memory error. Optional.
Example:
// get second page of records with each page having 100.let searchParameters = { offset:100, limit:100}
Specifying and limiting returned fields
fields_to_return (array) the fields to return. Optional.
Example:
let searchParameters = { fields_to_return: [ 'group_status','group_type','member_count','leaders','location_grid','last_modified','requires_updated' ]}
Bringing it all together
After building the filter parameters, we need to transform the searchParameters object in the query parameters string. The query string needs to be the same format that jQuery.param() outputs. See here for a plain js alternative
let searchParameters = { overall_status: ["active","-closed"],// -closed filters out the closed records seeker_path: ["none"], sort:"post_date", sources: ["instagram"]}let queryParametersString =jQuery.param(searchParameters)// this gives a string that looks like this:// seeker_path%5B%5D=none&overall_status%5B%5D=active&overall_status%5B%5D=-closed&sources%5B%5D=instagram&sort=post_date//query away with:let queryString =`https://example.com/wp-json/dt-posts/v2/contacts/?${queryParametersString}`;
Returns
//for contacts{ posts: [ { ... contact1 ... }, { ... contact2 ... } ], total:339// the total number of contacts available to page (see offset)}//for groups{ posts: [ { ... group1 ... }, { ... group2 ... } ], total:34// the total number of groups available to page (see offset)}