Settings Page Fields
How to get values from MetaBox Settings Page custom fields
MetaBox fields available in PRO
version only.
On this page will be shown examples how to get values of MetaBox custom fields related to Settings Page.
We have to use metabox_option_value
field of GraphQL RootQuery type to get value of any MetaBox field type.
This field is created based on rwmb_get_field MetaBox function and takes three arguments:
- option_name - here should be used
Option name
setting value of the Settings Page - field_id - here should be used
ID
setting value of the MetaBox custom field - args - extra arguments for some field types (like size for image_advanced) or for another object type (like getting values for terms or users). Format
param1=value1¶m2=value2
.
Returned value:
- If the field has a single value (not multiple nor clone), then the function returns that value.
- If the field has multiple values (multiple, clone, or the field type is group), then the function returns an array of values.
Depending on the field types, the returned value can be different. Please refer to each field type in the Fields section in MetaBox documentation for more details.
Some MetaBox field types(Post, Taxonomy, User, Group) have their own specific GraphQL fields to get values in advanced way.
Example for Autocomplete field:
- Query
- Result
query{
custom_autocomplete: metabox_option_value(option_name: "service", field_id: "custom_autocomplete")
}
- Non-Cloneable
- Cloneable
{
"custom_autocomplete": [
0: "css",
1: "javascript"
]
}
{
"custom_autocomplete": [
0: [
0: "css",
1: "javascript"
],
1: [
0: "javascript"
]
]
}
Example for Background field:
- Query
- Result
query{
custom_background: metabox_option_value(option_name: "service", field_id: "custom_background")
}
- Non-Cloneable
- Cloneable
{
"custom_background": {
"color": "#111222",
"image": "https://domain.com/wp-uploads/2017/12/bg.png",
"position": "top left",
"attachment": "fixed",
"size": "cover",
"repeat": "no-repeat"
}
}
{
"custom_background": [
0: {
"color": "#111222",
"image": "https://domain.com/wp-uploads/2017/12/bg1.png",
"position": "top left",
"attachment": "fixed",
"size": "cover",
"repeat": "no-repeat"
},
1: {
"color": "#111333",
"image": "https://domain.com/wp-uploads/2017/12/bg2.png",
"position": "top left",
"attachment": "fixed",
"size": "cover",
"repeat": "no-repeat"
}
]
}
Example for Button Group field:
- Query
- Result
query{
custom_button_group: metabox_option_value(option_name: "service", field_id: "custom_button_group")
}
- Non-Cloneable(single)
- Non-Cloneable(multiple)
- Cloneable(single)
- Cloneable(multiple)
{
"custom_button_group": "html"
}
{
"custom_button_group": [
0: "css",
1: "html"
]
}
{
"custom_button_group": [
0: "css",
1: "html"
]
}
{
"custom_button_group": [
0: [
0: "css",
1: "javascript"
],
1: [
0: "javascript"
]
]
}
Example for Checkbox List field:
- Query
- Result
query{
custom_checkbox_list: metabox_option_value(option_name: "service", field_id: "custom_checkbox_list")
}
- Non-Cloneable
- Cloneable
{
"custom_checkbox_list": [
0: "css",
1: "javascript"
]
}
{
"custom_checkbox_list": [
0: [
0: "css",
1: "javascript"
],
1: [
0: "javascript"
]
]
}
Example for Checkbox field:
- Query
- Result
query{
custom_checkbox: metabox_option_value(option_name: "service", field_id: "custom_checkbox")
}
- Non-Cloneable
- Cloneable
{
"custom_checkbox": 0
}
{
"custom_checkbox": [
0: 1
]
}
Example for Color Picker field:
- Query
- Result
query{
custom_color: metabox_option_value(option_name: "service", field_id: "custom_color")
}
- Non-Cloneable
- Cloneable
{
"custom_color": "#c9882e"
}
{
"custom_color": [
0: "#c9882e",
1: "#219128"
]
}
Example for Custom HTML field:
- Query
- Result
query{
custom_html: metabox_option_value(option_name: "service", field_id: "custom_html")
}
{
"custom_html": "<div class=\"alert alert-warning\">This is a custom HTML content</div>"
}
Example for Date field:
- Query
- Result
query{
custom_date: metabox_option_value(option_name: "service", field_id: "custom_date")
}
- Non-Cloneable
- Cloneable
{
"custom_date": "30-01-2019"
}
{
"custom_date": [
0: "25-01-2019",
1: "30-01-2019"
]
}
Example for Datetime field:
- Query
- Result
query{
custom_datetime: metabox_option_value(option_name: "service", field_id: "custom_datetime")
}
- Non-Cloneable
- Cloneable
{
"custom_datetime": "30-01-2019 09:30:00"
}
{
"custom_datetime": [
0: "25-01-2019 09:30:00",
1: "30-01-2019 09:30:00"
]
}
Example for Fieldset Text field:
- Query
- Result
query{
custom_fieldset: metabox_option_value(option_name: "service", field_id: "custom_fieldset")
}
- Non-Cloneable
- Cloneable
{
"custom_fieldset": {
"color": "#111222",
"position": "top left",
"attachment": "fixed",
"size": "cover"
}
}
{
"custom_fieldset": [
0: {
"color": "#111222",
"position": "top left",
"attachment": "fixed",
"size": "cover"
},
1: {
"color": "#111333",
"position": "top left",
"attachment": "fixed",
"size": "cover"
}
]
}
Example for File Input field:
- Query
- Result
query{
custom_file_input: metabox_option_value(option_name: "service", field_id: "custom_file_input")
}
- Non-Cloneable
- Cloneable
{
"custom_file_input": "url": "https://example.com/wp-content/uploads/intro.txt"
}
{
"custom_file_input": [
0: "https://example.com/wp-content/uploads/intro.txt",
1: "https://example.com/wp-content/uploads/intro2.txt"
]
}
Example for File field:
Same query and results valid for File Advanced
, File Upload
fields.
- Query
- Result
query{
custom_file: metabox_option_value(option_name: "service", field_id: "custom_file")
}
- Non-Cloneable
- Cloneable
{
"custom_file": {
"ID": 123,
"name": "intro.txt",
"path": "/var/www/wp-content/uploads/intro.txt",
"url": "https://example.com/wp-content/uploads/intro.txt",
"title": "Introduction"
}
}
{
"custom_file": [
0: {
"ID": 123,
"name": "intro.txt",
"path": "/var/www/wp-content/uploads/intro.txt",
"url": "https://example.com/wp-content/uploads/intro.txt",
"title": "Introduction"
},
1: {
"ID": 124,
"name": "intro2.txt",
"path": "/var/www/wp-content/uploads/intro2.txt",
"url": "https://example.com/wp-content/uploads/intro2.txt",
"title": "Introduction2"
}
]
}
Example for Image Select field:
- Query
- Result
query{
custom_image_select: metabox_option_value(option_name: "service", field_id: "custom_image_select")
}
- Non-Cloneable(single)
- Non-Cloneable(multiple)
- Cloneable(single)
- Cloneable(multiple)
{
"custom_image_select": "https://example.com/wp-content/uploads/logo-150x80.png"
}
{
"custom_image_select": [
0: "https://example.com/wp-content/uploads/logo-150x80.png",
1: "https://example.com/wp-content/uploads/logo-150x150.png"
]
}
{
"custom_image_select": [
0: "https://example.com/wp-content/uploads/logo-150x80.png",
1: "https://example.com/wp-content/uploads/logo-150x150.png"
]
}
{
"custom_image_select": [
0: [
0: "https://example.com/wp-content/uploads/logo-150x80.png",
1: "https://example.com/wp-content/uploads/logo-150x150.png"
],
1: [
0: "https://example.com/wp-content/uploads/logo-150x150.png"
]
]
}
Example for Image field:
Same query and results valid for Image Advanced
, Image Upload
, Single Image
fields.
- Query
- Result
query{
custom_image: metabox_option_value(option_name: "service", field_id: "custom_image")
}
- Non-Cloneable
- Cloneable
{
"custom_image": {
"ID" : 123,
"name": "logo-150x80.png",
"path": "/var/www/wp-content/uploads/logo-150x80.png",
"url": "https://example.com/wp-content/uploads/logo-150x80.png",
"width": 150,
"height": 80,
"full_url": "https://example.com/wp-content/uploads/logo.png",
"title": "Logo",
"caption": "Logo caption",
"description": "Used in the header",
"alt": "Logo ALT text",
"srcset": "large.jpg 1920w, medium.jpg 960w, small.jpg 480w",
"sizes": [],
"image_meta": []
}
}
{
"custom_image": [
0: {
"ID" : 123,
"name": "logo-150x80.png",
"path": "/var/www/wp-content/uploads/logo-150x80.png",
"url": "https://example.com/wp-content/uploads/logo-150x80.png",
"width": 150,
"height": 80,
"full_url": "https://example.com/wp-content/uploads/logo.png",
"title": "Logo",
"caption": "Logo caption",
"description": "Used in the header",
"alt": "Logo ALT text",
"srcset": "large.jpg 1920w, medium.jpg 960w, small.jpg 480w",
"sizes": [],
"image_meta": []
},
1: {
"ID" : 124,
"name": "logo2-150x80.png",
"path": "/var/www/wp-content/uploads/logo2-150x80.png",
"url": "https://example.com/wp-content/uploads/logo2-150x80.png",
"width": 150,
"height": 80,
"full_url": "https://example.com/wp-content/uploads/logo2.png",
"title": "Logo",
"caption": "Logo caption",
"description": "Used in the header",
"alt": "Logo ALT text",
"srcset": "large.jpg 1920w, medium.jpg 960w, small.jpg 480w",
"sizes": [],
"image_meta": []
}
]
}
Example for Image field with specified size:
Same query and results valid for Image Advanced
, Image Upload
, Single Image
fields.
- Query
- Result
query{
custom_image: metabox_option_value(option_name: "service", field_id: "custom_image", args: "size=thumbnail")
}
- Non-Cloneable
- Cloneable
{
"custom_image": {
"ID" : 123,
"name": "logo-150x80.png",
"path": "/var/www/wp-content/uploads/logo-150x80.png",
"url": "https://example.com/wp-content/uploads/logo-150x80.png",
"width": 150,
"height": 80,
"full_url": "https://example.com/wp-content/uploads/logo.png",
"title": "Logo",
"caption": "Logo caption",
"description": "Used in the header",
"alt": "Logo ALT text",
"srcset": "large.jpg 1920w, medium.jpg 960w, small.jpg 480w",
"sizes": [],
"image_meta": []
}
}
{
"custom_image": [
0: {
"ID" : 123,
"name": "logo-150x80.png",
"path": "/var/www/wp-content/uploads/logo-150x80.png",
"url": "https://example.com/wp-content/uploads/logo-150x80.png",
"width": 150,
"height": 80,
"full_url": "https://example.com/wp-content/uploads/logo.png",
"title": "Logo",
"caption": "Logo caption",
"description": "Used in the header",
"alt": "Logo ALT text",
"srcset": "large.jpg 1920w, medium.jpg 960w, small.jpg 480w",
"sizes": [],
"image_meta": []
},
1: {
"ID" : 124,
"name": "logo2-150x80.png",
"path": "/var/www/wp-content/uploads/logo2-150x80.png",
"url": "https://example.com/wp-content/uploads/logo2-150x80.png",
"width": 150,
"height": 80,
"full_url": "https://example.com/wp-content/uploads/logo2.png",
"title": "Logo",
"caption": "Logo caption",
"description": "Used in the header",
"alt": "Logo ALT text",
"srcset": "large.jpg 1920w, medium.jpg 960w, small.jpg 480w",
"sizes": [],
"image_meta": []
}
]
}
Example for Post field (basic method):
- Query
- Result
query{
custom_post: metabox_option_value(option_name: "service", field_id: "custom_post")
}
- Non-Cloneable(single)
- Non-Cloneable(multiple)
- Cloneable(single)
- Cloneable(multiple)
{
"custom_post": 123
}
{
"custom_post": [
0: 123,
1: 124
]
}
{
"custom_post": [
0: 123,
1: 124
]
}
{
"custom_post": [
0: [
0: 123,
1: 124
],
1: [
0: 130
]
]
}
Example for Post field with single value (advanced method):
GraphQL RootQuery type has field metabox_option_post_value
which purpose is to get value of non-cloneable and non-multiple MetaBox Post field.
But comparing to metabox_option_value
(which returns just Post ID) - metabox_option_post_value
returns Post GraphQL type.
This method gives us more power and flexibility:
- we can get just necessary fields of Post
- we can get meta values of this Post
- we can get FeaturedImage of this Post
- we can get own MetaBox fields of this Post
- Query
- Result
query{
custom_post_object: metabox_option_post_value(option_name: "service", field_id: "custom_post") {
ID
post_title
post_content
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
}
{
"custom_post": {
"ID": 53,
"post_title": "Sequi qui blanditiis provident",
"post_content": " <here will be rendered post content, Gutenberg blocks will be rendered>",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
}
}
Example for Post field with multiple values (advanced method):
GraphQL RootQuery type has field metabox_option_multiple_post_value
which purpose is to get value of cloneable or multiple MetaBox Post field.
But comparing to metabox_option_value
(which returns array of Post IDs if MetaBox Post field is cloneable or multiple) - metabox_option_multiple_post_value
returns array of Post GraphQL types.
- Query
- Result
query{
custom_multiple_post: metabox_option_multiple_post_value(option_name: "service", field_id: "custom_multiple_post") {
ID
post_title
post_content
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
}
{
"custom_multiple_post": [
0: {
"ID": 53,
"post_title": "Sequi qui blanditiis provident",
"post_content": " <here will be rendered post content, Gutenberg blocks will be rendered>",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
},
1: {
"ID": 54,
"post_title": "Sequi qui blanditiis",
"post_content": " <here will be rendered post content, Gutenberg blocks will be rendered>",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
}
]
}
Example for Taxonomy field (basic method):
- Query
- Result
query{
custom_taxonomy: metabox_option_value(option_name: "service", field_id: "custom_taxonomy")
}
- Non-Multiple
- Multiple
{
"custom_taxonomy": {
"term_id":1
"name":"Uncategorized"
"slug":"uncategorized"
"term_group":0
"term_taxonomy_id":1
"taxonomy":"category"
"description":""
"parent":0
"count":21
"filter":"raw"
}
}
{
"custom_taxonomy": [
0:{
"term_id":1
"name":"Uncategorized"
"slug":"uncategorized"
"term_group":0
"term_taxonomy_id":1
"taxonomy":"category"
"description":""
"parent":0
"count":21
"filter":"raw"
}
]
}
Example for Taxonomy field with single value (advanced method):
Same query and results valid for Taxonomy Advanced
field.
GraphQL RootQuery type has field "metabox_option_taxonomy_value" which purpose is to get value of non-multiple MetaBox Taxonomy field.
But comparing to "metabox_option_value" - "metabox_option_taxonomy_value" returns Term GraphQL type.
This method gives us more power and flexibility:
- we can get just necessary fields of Term
- we can get meta values of this Term
- we can get own MetaBox fields of this Term
- Query
- Result
query{
custom_taxonomy: metabox_option_taxonomy_value(option_name: "service", field_id: "custom_taxonomy") {
term_id
slug
description
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
}
{
"custom_term": {
"term_id": 1,
"slug": "uncategorized",
"description": "Uncategorized",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
}
}
Example for Taxonomy field with multiple values (advanced method):
GraphQL RootQuery type has field "metabox_option_multiple_taxonomy_value" which purpose is to get value of multiple MetaBox Taxonomy field.
"metabox_option_multiple_taxonomy_value" always returns array of GraphQL Term types(of course if field is multiple).
- Query
- Result
query{
custom_taxonomy: metabox_option_multiple_taxonomy_value(option_name: "service", field_id: "custom_taxonomy") {
term_id
slug
description
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
}
{
"custom_term":[
"0":{
"term_id":1,
"slug":"uncategorized",
"description":"Uncategorized",
"some_meta_key":"<here will be meta value>",
"custom_metabox_value":"<here will be value of MetaBox field>"
},
"1":{
"term_id":2,
"slug":"categorized",
"description":"Categorized",
"some_meta_key":"<here will be meta value>",
"custom_metabox_value":"<here will be value of MetaBox field>"
}
]
}
Example for User field (basic method):
- Query
- Result
query{
custom_user: metabox_option_value(option_name: "service", field_id: "custom_user")
}
- Non-Cloneable(single)
- Non-Cloneable(multiple)
- Cloneable(single)
- Cloneable(multiple)
{
"custom_user": 123
}
{
"custom_user": [
0: 123,
1: 124
]
}
{
"custom_user": [
0: 123,
1: 124
]
}
{
"custom_user": [
0: [
0: 123,
1: 124
],
1: [
0: 130
]
]
}
Example for User field with single value (advanced method):
GraphQL RootQuery type has field "metabox_option_user_value" which purpose is to get value of non-cloneable and non-multiple MetaBox User field.
But comparing to metabox_option_value
(which returns just User ID) - metabox_option_post_value
returns User GraphQL type.
This method gives us more power and flexibility:
- we can get just necessary fields of User
- we can get meta values of this User
- we can get own MetaBox fields of this User
- Query
- Result
query{
custom_user: metabox_option_user_value(option_name: "service", field_id: "custom_user") {
ID
display_name
user_email
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
}
{
"custom_user": {
"ID": 1,
"display_name": "admin",
"user_email": "[email protected]",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
}
}
Example for User field with multiple values (advanced method):
GraphQL RootQuery type has field "metabox_option_multiple_user_value" which purpose is to get value of cloneable or multiple MetaBox User field.
But comparing to metabox_option_value
(which returns array of User IDs if MetaBox Post field is cloneable or multiple) - metabox_option_multiple_user_value
returns array of User GraphQL types.
- Query
- Result
query{
custom_multiple_users: metabox_option_multiple_user_value(option_name: "service", field_id: "custom_user") {
ID
display_name
user_email
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
}
{
"custom_multiple_users":[
{
"ID":1,
"display_name":"admin",
"user_email":"[email protected]",
"some_meta_key":"<here will be meta value>",
"custom_metabox_value":"<here will be value of MetaBox field>"
},
{
"ID":2,
"display_name":"admin2",
"user_email":"[email protected]",
"some_meta_key":"<here will be meta value>",
"custom_metabox_value":"<here will be value of MetaBox field>"
}
]
}
Example for Group field (basic method):
- Query
- Result
query{
custom_group: metabox_option_value(option_name: "service", field_id: "custom_group")
}
- Non-Cloneable
- Cloneable
{
"custom_group": {
"text": "My custom text",
"post": 123,
"user": 1
}
}
{
"custom_group": [
0:{
"text": "My custom text1",
"post": 123,
"user": 1
},
1:{
"text": "My custom text2",
"post": 124,
"user": 2
}
]
}
Example for Group field with single value (advanced method):
GraphQL RootQuery type has field "metabox_option_group_value" which purpose is to get value of non-cloneable MetaBox Group field.
But comparing to "metabox_option_value" - "metabox_option_group_value" returns GraphQL MetaBoxGroupField type(MetaBoxGroupField has all metabox related GraphQL fields).
This method gives us more power and flexibility:
- we can get just necessary sub fields of MetaBoxGroupField
- if one of sub fields has MetaBox Post type, we can use
metabox_post_value
to get value of this sub field - if one of sub fields has MetaBox Taxonomy type, we can use
metabox_taxonomy_value
to get value of this sub field - if one of sub fields has MetaBox User type, we can use
metabox_user_value
to get value of this sub field - if one of sub fields has MetaBox Group type, we can use
metabox_group_value
to get value of this sub field
- Query
- Result
query{
custom_group: metabox_option_group_value(option_name: "service", field_id: "custom_group") {
text: metabox_value(field_id: "text")
post: metabox_post_value(field_id: "post_object") {
ID
post_title
post_content
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
user: metabox_user_value(field_id: "user") {
ID
display_name
user_email
}
}
}
{
"custom_group": {
"text": "custom text",
"post": {
"ID": 47,
"post_title": "Omnis nesciunt quasi amet officiis",
"post_content": "<here will be rendered post content, Gutenberg blocks will be rendered>",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
},
"user": {
"ID": 1,
"display_name": "admin",
"user_email": "[email protected]",
}
}
}
Example for Group field with multiple values (advanced method):
GraphQL RootQuery type has field "metabox_option_multiple_group_value" which purpose is to get value of cloneable MetaBox Group field.
But comparing to "metabox_option_value" - "metabox_option_multiple_group_value" returns array of GraphQL MetaBoxGroupField types(MetaBoxGroupField has all metabox related GraphQL fields).
This method gives us more power and flexibility:
- we can get just necessary sub fields of MetaBoxGroupField
- if one of sub fields has MetaBox Post type, we can use
metabox_post_value
to get value of this sub field - if one of sub fields has MetaBox Taxonomy type, we can use
metabox_taxonomy_value
to get value of this sub field - if one of sub fields has MetaBox User type, we can use
metabox_user_value
to get value of this sub field - if one of sub fields has MetaBox Group type, we can use
metabox_group_value
to get value of this sub field
- Query
- Result
query{
custom_group: metabox_option_multiple_group_value(option_name: "service", field_id: "custom_group") {
text: metabox_value(field_id: "text")
post: metabox_post_value(field_id: "post_object") {
ID
post_title
post_content
some_meta_key: meta_value(key: "some_meta_key")
custom_metabox_value: metabox_value(field_id: "custom_metabox_field_name")
}
user: metabox_user_value(field_id: "user") {
ID
display_name
user_email
}
}
}
{
"custom_group": [
0:{
"text": "custom text",
"post": {
"ID": 47,
"post_title": "Omnis nesciunt quasi amet officiis",
"post_content": "<here will be rendered post content, Gutenberg blocks will be rendered>",
"some_meta_key": "<here will be meta value>",
"custom_metabox_value": "<here will be value of MetaBox field>"
},
"user": {
"ID": 1,
"display_name": "admin",
"user_email": "[email protected]",
}
}
]
}