Select plugin version:
Since version: v1.4.0
GraphQL
The table field can be read and updated with GraphQL.
Requirements
To use GraphQL in WordPress and with the table field, you need the plugins WPGraphQL and WPGraphQL for ACF installed and activated.
Get table data
GraphQL query example for a post
query GetPage {
page(id: "123", idType: DATABASE_ID) {
yourFieldGroup {
tableFieldName
}
}
}
Gets the table data of a page with post ID "123" from fieldgroup "yourFieldGroup" with field name "table_field_name". Note that field names written with underscores must be queried as camelcase in GraphQL.
GraphQL query return
{
"data": {
"page": {
"tableFieldGroup": {
"tableFieldName": "{"t":{"o":{"ct":"st","cols":1,"rows":1,"uf":"n","uh":"n","tb":"","changed":true}},"c":[{"c":[{"c":"","o":[]}],"o":[]}],"b":[{"c":[{"c":"Hello Table","o":[]}],"o":[]}],"f":[{"c":[{"c":"","o":[]}],"o":[]}],"h":[{"c":[{"c":"","o":[]}],"o":[]}],"p":{"v":"1.2.10","fk":"field_664dcdcdd4983","fn":"table_field_name"}}"
}
}
}
}
The return is a JSON representation of the table fields data. The table data remains unformatted unless the parent field type is 'repeater,' 'flexible_content,' or 'clone.' Currently, no WPGraphQL filter is available to resolve this. To get the table HTML, you can pass the JSON string to get_table()
or use the table_manager()
to edit the table and also output it as HTML.
Update table data
Updating a table field via GraphQL is done internally using the update_field()
function. If you’re working with different field group locations, nested fields, repeaters, and flexible content, the explanations for the post ID and field selector in the update_field() instructions apply.
GraphQL query example for a post
mutation MyMutation {
updateTablefieldPro(
input: {postID: "123", selector: "tableFieldName", tableJSON: "{"t":{"o":{"ct":"st","cols":1,"rows":1,"uf":"n","uh":"n","tb":"","changed":true}},"c":[{"c":[{"c":"","o":[]}],"o":[]}],"b":[{"c":[{"c":"Hello Table","o":[]}],"o":[]}],"f":[{"c":[{"c":"","o":[]}],"o":[]}],"h":[{"c":[{"c":"","o":[]}],"o":[]}],"p":{"v":"1.2.10","fk":"field_664dcdcdd4983","fn":"table_field_name"}}", clientMutationId: "update_table"}
) {
clientMutationId
postID
return
}
}
Updates the table data of a page with post ID "123" with field name "table_field_name". Note that field names written with underscores must be queried as camelcase in GraphQL. The table JSON can be generated from unformatted or formatted table data.
GraphQL query return
{
"data": {
"updateTablefieldPro": {
"clientMutationId": "update_table",
"postID": "123",
"return": "true",
}
}
}
return
returns the update_field() return value.