GutenBricks
  • ๐Ÿš€ Getting Started
    • Next: Common Troubleshooting Issues
    • Next: Configure Page Template to render
    • Next: Manage Block using Template Bundles
    • ๐Ÿค”Most common troubleshooting step
  • ๐ŸŒŸFeatures
    • Working with Elements
    • Variants
      • Value Binding
    • InnerBlock
    • Fine-Tune Text Editing
    • Dynamic Class
    • Code Block with Dynamic Data
    • ๐Ÿ’กQuick Tips
      • Dynamic Short Code
      • Accordion Block using InnerBlock
    • โšกAdvanced
      • Custom Block HTML ID
      • Value Binding (coming soon)
      • Creating "comments and docs" inside a template
      • Globally Updating Block Styles
      • Block Wrapper Dynamic Class
      • Working with WPML or Polylang
    • ๐ŸงญRoad Map
  • ๐Ÿ€Dynamic Data
    • GB:Meta
    • ACF
      • Setting Up ACF
      • Post Object Field (in-progress)
    • Meta Box
      • Setting Up Meta Box (In-progress)
      • Post Field (in-progress)
    • Built-in GutenBricks Dynamic Data
  • ๐ŸฐClient Experience
    • Documenting Blocks
    • Custom Block Preview
    • Custom Pop-up Text
    • Default Page Template
  • ๐Ÿ› ๏ธCustomizing Gutenberg
    • Gutenberg Editor Custom CSS
      • CSS Snippet: Make the block section not full height for ACSS
  • ๐ŸคนResources
    • ๐Ÿ‘ฉโ€๐Ÿ’ป Developer API
      • echo:gb_current_element_id returns unique ID
      • GutenBricks Events for Gutenberg Editor
      • gb_get_field()
      • Unique IDs
      • Filter: gutenbricks_bricks_theme_name
    • ๐Ÿ”Œ Third Party Integrations
      • ACSS integration with GutenBricks
        • ACSS 2.8.0 Section padding missing
      • ACF / Meta Box integration
    • โค๏ธ Our Approach and Philosophy
  • ๐Ÿ“– Changelog
    • Known issues and bugs
    • Current Changelog
    • Past Changelog
      • v1.1-RC (Released as v1.1.0)
      • v1.0-RC (Released as v1.0)
Powered by GitBook
On this page
  1. Resources
  2. ๐Ÿ‘ฉโ€๐Ÿ’ป Developer API

gb_get_field()

This method allows you to retrieve Block metadata programmatically.

Experimental Feature @since v1.0.0-RC4.2.0

A GutenBricks block can store meta value. If you're using ACF or Metabox fields to create input fields, their values are saved within the block. The values are retrieve as dynamic data in Bricks (For eg. {acf_example})

Sometimes, the code editor you're working on may not support dynamic data or has no access to meta data saved in Blocks. For example, the PHP editor inside Bricks Builder's Query Loop does not access Block meta data.

In this case, you can use gb_get_field($key, $post_id, $args) function to retrieve the value instead.

  • This method works for both ACF and Metabox.

  • The retrieving hierarchy:

    • First, it will look for data stored within the block

    • If not, it returns the value saved on other related sources such as page or template

Example:

<?php
// for ACF
if (function_exists('gb_get_field')) {
  $value = gb_get_field('acf_my_value');
}
// for Metabox
if (function_exists('gb_get_field')) {
  $value = gb_get_field('mb_bricks_template_my_value');
}

get_gutenbricks_meta($key, $post_id, $args)

$key (required): key value that you would use inside Bricks builder to retrieve the dynamic data. You will need acf_ and mb_bricks_template_ prefixes for them

$post_id (optional): Post, page or CPT where you want to retrieve the data from

$args (optional): $arg parameter for Metabox's rwmb_get_value(). Ignored when the dynamic data is from ACF.

PreviousGutenBricks Events for Gutenberg EditorNextUnique IDs

Last updated 1 year ago

๐Ÿคน