PhP Function Output
Call any PHP function directly from GraphQL queries using php_function_output() Pro Feature. This extends your queries with core PHP functions, WordPress functions, plugin functions, and custom PHP functions.
PHP Function Output Syntax
- Syntax
- Example
- JSON Output
Call any PHP function directly from GraphQL queries using php_function_output():
General syntax:
php_function_output(
function: "function_name"
arguments: [arg1, arg2, arg3]
fallback: default_value
)
Parameters:
function(required) - Name of the PHP function to callarguments(optional) - Array of arguments to pass to the functionfallback(optional) - Default value if function fails or doesn't exist
Basic usage examples:
{
# Function with no arguments
current_time: php_function_output(function: "time")
# Function with single argument
uppercase: php_function_output(
function: "strtoupper",
arguments: ["hello world"]
)
# Function with multiple arguments
formatted_date: php_function_output(
function: "date",
arguments: ["Y-m-d H:i:s", 1234567890]
)
# Function with fallback value
safe_option: php_function_output(
function: "get_option",
arguments: ["my_custom_option"],
fallback: "default_value"
)
}
JSON response from the example:
{
"current_time": 1701234567,
"uppercase": "HELLO WORLD",
"formatted_date": "2009-02-13 23:31:30",
"safe_option": "default_value"
}
The function returns whatever the PHP function returns - could be strings, numbers, arrays, objects, or boolean values depending on the function called.
WordPress Functions
- Simple
- With Arguments
- Post Context
Functions that don't require arguments:
{
# Check if user is logged in
is_logged_in: php_function_output(function: "is_user_logged_in")
# Get current user ID
current_user_id: php_function_output(function: "get_current_user_id")
# Get site information
site_logo: php_function_output(function: "get_site_icon_url")
site_url: php_function_output(function: "home_url")
}
Functions that need parameters:
{
# Get specific option values
contact_email: php_function_output(
function: "get_option",
arguments: ["admin_email"]
)
# Get theme customizer values
header_color: php_function_output(
function: "get_theme_mod",
arguments: ["header_textcolor"],
fallback: "#000000"
)
# Check if plugin is active
woo_active: php_function_output(
function: "is_plugin_active",
arguments: ["woocommerce/woocommerce.php"]
)
# Get permalink for specific post
about_page_url: php_function_output(
function: "get_permalink",
arguments: [21]
)
}
Using current post data in function calls:
{
post {
ID
post_title
# Get post meta values
view_count: php_function_output(
function: "get_post_meta",
arguments: ["{{wp.post.ID}}", "post_views", true]
)
# Get categories for current post
category_names: php_function_output(
function: "wp_get_post_categories",
arguments: ["{{wp.post.ID}}", {"fields": "names"}]
)
# Check if post has specific tag
has_featured_tag: php_function_output(
function: "has_tag",
arguments: ["featured", "{{wp.post.ID}}"]
)
}
}
Plugin Integration Examples
Access plugin-specific functions for extended functionality:
- ACF Functions
- WooCommerce
- MetaBox
{
# Get ACF options page values
company_logo: php_function_output(
function: "get_field",
arguments: ["company_logo", "option"]
)
# Get all field groups
field_groups: php_function_output(
function: "acf_get_field_groups"
)
# Get field configuration
hero_field_config: php_function_output(
function: "acf_get_field",
arguments: ["field_hero_image"]
)
post {
# Get formatted ACF value
formatted_date: php_function_output(
function: "get_field",
arguments: ["event_date", "{{wp.post.ID}}", false]
)
}
}
{
post {
# Get product data (if current post is a product)
product_price: php_function_output(
function: "get_post_meta",
arguments: ["{{wp.post.ID}}", "_price", true]
)
sale_price: php_function_output(
function: "get_post_meta",
arguments: ["{{wp.post.ID}}", "_sale_price", true]
)
is_on_sale: php_function_output(
function: "get_post_meta",
arguments: ["{{wp.post.ID}}", "_sale_price", true]
)
}
# Get WooCommerce settings
currency: php_function_output(
function: "get_woocommerce_currency"
)
# Check if WooCommerce page
is_shop: php_function_output(function: "is_shop")
is_cart: php_function_output(function: "is_cart")
}
{
# Get MetaBox field settings
contact_field_settings: php_function_output(
function: "rwmb_get_field_settings",
arguments: ["contact_email"]
)
# Get all fields from a meta box
contact_fields: php_function_output(
function: "rwmb_get_object_fields",
arguments: ["contact_info", "post"]
)
post {
# Get formatted MetaBox value
formatted_content: php_function_output(
function: "rwmb_the_value",
arguments: ["custom_content", "", "{{wp.post.ID}}"]
)
}
}
Complex Argument Structure
{
# Get related posts & exclude current post
post {
ID
related: php_function_output(
function: "get_posts",
arguments: [{
post_type: "post",
posts_per_page: 3,
post_not_in: ["{{ID}}"]
}]
)
}
}
GraphQL Variables in PHP Function Output
Variable syntax
{{field_name}}- Data from current object (post, user, term)[[global_variable]]- Site-wide data or custom query results
{
post {
ID @private
post_title @private
# Use current post title and site title from built-in Data Variable in function
custom_title: php_function_output(
function: "sprintf",
arguments: ["%s - %s", "{{post_title}}", "[[wp.site_title]]"]
)
}
}
php_function_output applies security restrictions to prevent database modifications:
This is an important Builderius feature, and prevents a whole class of security breaches that plague other visual builders.
❌ You cannot use wp_insert_post(), wp_update_post()
❌ You cannot use wp_insert_user(), update_user_meta()
❌ You cannot execute INSERT, UPDATE, DELETE queries
✅ You can use any read-only function (get_*, wp_get_*, is_*, has_*)
Always provide fallbacks for:
- Plugin functions that might not exist
- Functions that depend on external data
- Custom functions from themes or plugins
Use php_function_output() to bridge the gap between GraphQL queries and the full WordPress PHP ecosystem, enabling access to any WordPress, plugin, or custom functionality within your templates.