Skip to main content

Settings Page Fields

How to get values from Meta Box Settings Page custom fields

info

Meta Box fields available in PRO version only.

On this page will be shown examples how to get values of Meta Box custom fields related to Settings Page.

We have to use metabox_option_value field of GraphQL RootQuery type to get value of any Meta Box field type. This field is created based on [rwmb_get_field](https://docs.Meta Box.io/functions/rwmb-get-value/) Meta Box 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 Meta Box 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&param2=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.
info

Depending on the field types, the returned value can be different. Please refer to each field type in the [Fields](https://docs.Meta Box.io/fields/) section in Meta Box documentation for more details.

note

Some Meta Box field types(Post, Taxonomy, User, Group) have their own specific GraphQL fields to get values in advanced way.

Example for Autocomplete field:

query{
custom_autocomplete: metabox_option_value(option_name: "service", field_id: "custom_autocomplete")
}

Example for Background field:

query{
custom_background: metabox_option_value(option_name: "service", field_id: "custom_background")
}

Example for Button Group field:

query{
custom_button_group: metabox_option_value(option_name: "service", field_id: "custom_button_group")
}

Example for Checkbox List field:

query{
custom_checkbox_list: metabox_option_value(option_name: "service", field_id: "custom_checkbox_list")
}

Example for Checkbox field:

query{
custom_checkbox: metabox_option_value(option_name: "service", field_id: "custom_checkbox")
}

Example for Color Picker field:

query{
custom_color: metabox_option_value(option_name: "service", field_id: "custom_color")
}

Example for Custom HTML field:

query{
custom_html: metabox_option_value(option_name: "service", field_id: "custom_html")
}

Example for Date field:

query{
custom_date: metabox_option_value(option_name: "service", field_id: "custom_date")
}

Example for Datetime field:

query{
custom_datetime: metabox_option_value(option_name: "service", field_id: "custom_datetime")
}

Example for Fieldset Text field:

query{
custom_fieldset: metabox_option_value(option_name: "service", field_id: "custom_fieldset")
}

Example for File Input field:

query{
custom_file_input: metabox_option_value(option_name: "service", field_id: "custom_file_input")
}

Example for File field:

Same query and results valid for File Advanced, File Upload fields.

query{
custom_file: metabox_option_value(option_name: "service", field_id: "custom_file")
}

Example for Image Select field:

query{
custom_image_select: metabox_option_value(option_name: "service", field_id: "custom_image_select")
}

Example for Image field:

Same query and results valid for Image Advanced, Image Upload, Single Image fields.

query{
custom_image: metabox_option_value(option_name: "service", field_id: "custom_image")
}

Example for Image field with specified size:

Same query and results valid for Image Advanced, Image Upload, Single Image fields.

query{
custom_image: metabox_option_value(option_name: "service", field_id: "custom_image", args: "size=thumbnail")
}

Example for Post field (basic method):

query{
custom_post: metabox_option_value(option_name: "service", field_id: "custom_post")
}

Example for Post field with single value (advanced method):

info

GraphQL RootQuery type has field metabox_option_post_value which purpose is to get value of non-cloneable and non-multiple Meta Box 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 Meta Box fields of this Post
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")
}
}

Example for Post field with multiple values (advanced method):

info

GraphQL RootQuery type has field metabox_option_multiple_post_value which purpose is to get value of cloneable or multiple Meta Box Post field.

But comparing to metabox_option_value(which returns array of Post IDs if Meta Box Post field is cloneable or multiple) - metabox_option_multiple_post_value returns array of Post GraphQL types.

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")
}
}

Example for Taxonomy field (basic method):

query{
custom_taxonomy: metabox_option_value(option_name: "service", field_id: "custom_taxonomy")
}

Example for Taxonomy field with single value (advanced method):

Same query and results valid for Taxonomy Advanced field.

info

GraphQL RootQuery type has field "metabox_option_taxonomy_value" which purpose is to get value of non-multiple Meta Box 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 Meta Box fields of this Term
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")
}
}

Example for Taxonomy field with multiple values (advanced method):

info

GraphQL RootQuery type has field "metabox_option_multiple_taxonomy_value" which purpose is to get value of multiple Meta Box Taxonomy field.

"metabox_option_multiple_taxonomy_value" always returns array of GraphQL Term types(of course if field is multiple).

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")
}
}

Example for User field (basic method):

query{
custom_user: metabox_option_value(option_name: "service", field_id: "custom_user")
}

Example for User field with single value (advanced method):

info

GraphQL RootQuery type has field "metabox_option_user_value" which purpose is to get value of non-cloneable and non-multiple Meta Box 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 Meta Box fields of this User
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")
}
}

Example for User field with multiple values (advanced method):

info

GraphQL RootQuery type has field "metabox_option_multiple_user_value" which purpose is to get value of cloneable or multiple Meta Box User field.

But comparing to metabox_option_value(which returns array of User IDs if Meta Box Post field is cloneable or multiple) - metabox_option_multiple_user_value returns array of User GraphQL types.

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")
}
}

Example for Group field (basic method):

query{
custom_group: metabox_option_value(option_name: "service", field_id: "custom_group")
}

Example for Group field with single value (advanced method):

info

GraphQL RootQuery type has field "metabox_option_group_value" which purpose is to get value of non-cloneable Meta Box Group field.

But comparing to "metabox_option_value" - "metabox_option_group_value" returns GraphQL MetaBoxGroupField type(MetaBoxGroupField has all Meta Box 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 Meta Box Post type, we can use metabox_post_value to get value of this sub field
  • if one of sub fields has Meta Box Taxonomy type, we can use metabox_taxonomy_value to get value of this sub field
  • if one of sub fields has Meta Box User type, we can use metabox_user_value to get value of this sub field
  • if one of sub fields has Meta Box Group type, we can use metabox_group_value to get value of this sub field
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
}
}
}

Example for Group field with multiple values (advanced method):

info

GraphQL RootQuery type has field "metabox_option_multiple_group_value" which purpose is to get value of cloneable Meta Box Group field.

But comparing to "metabox_option_value" - "metabox_option_multiple_group_value" returns array of GraphQL MetaBoxGroupField types(MetaBoxGroupField has all Meta Box 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 Meta Box Post type, we can use metabox_post_value to get value of this sub field
  • if one of sub fields has Meta Box Taxonomy type, we can use metabox_taxonomy_value to get value of this sub field
  • if one of sub fields has Meta Box User type, we can use metabox_user_value to get value of this sub field
  • if one of sub fields has Meta Box Group type, we can use metabox_group_value to get value of this sub field
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
}
}
}