Below, you’ll find a detailed guide on how to add the Meta Box – WordPress Custom Fields Framework Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Meta Box – WordPress Custom Fields Framework Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Meta Box – WordPress Custom Fields Framework Plugin and the shortcodes it provides:
"Meta Box – WordPress Custom Fields Framework plugin is a powerful tool for creating custom fields and meta boxes in WordPress. It simplifies customization, enhancing your site's functionality."
- [rwmb_meta]
Meta Box – WordPress Custom Fields Framework [rwmb_meta] Shortcode
The Meta Box shortcode allows for the extraction and display of custom field data. This shortcode accepts attributes like ‘id’, ‘object_id’, and ‘attribute’. It checks if the ‘id’ attribute is empty and if so, returns an empty string. The ‘id’ and ‘object_id’ attributes are used to get the value of the custom field. If ‘render_shortcodes’ is set to true, any shortcodes in the value are processed.
Shortcode: [rwmb_meta]
Parameters
Here is a list of all possible rwmb_meta shortcode parameters and attributes:
id
– Unique identifier for the meta fieldobject_id
– The ID of the post or user to fetch metadata fromattribute
– Additional attributes for the fieldrender_shortcodes
– Determines if shortcodes within the field value should be rendered
Examples and Usage
Basic example – A shortcode that uses the ‘rwmb_meta’ function to fetch a specific meta field value by its ID.
[rwmb_meta id='meta_field_id' /]
Advanced examples
Displaying a meta field value by its ID, but also specifying the object ID. This is useful when you want to fetch a meta field value from a specific post or page.
[rwmb_meta id='meta_field_id' object_id='123' /]
Displaying a meta field value by its ID, specifying the object ID, and disabling the rendering of nested shortcodes within the meta field value.
[rwmb_meta id='meta_field_id' object_id='123' render_shortcodes='false' /]
Displaying a meta field value by its ID, specifying the object ID, and defining a custom attribute. This is useful when you want to pass additional parameters to the shortcode.
[rwmb_meta id='meta_field_id' object_id='123' attribute='custom_attribute' /]
PHP Function Code
In case you have difficulties debugging what causing issues with [rwmb_meta]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'rwmb_meta', [ $this, 'register_shortcode' ] );
Shortcode PHP function:
function register_shortcode( $atts ) {
$atts = wp_parse_args( $atts, [
'id' => '',
'object_id' => null,
'attribute' => '',
'render_shortcodes' => 'true',
] );
Arr::change_key( $atts, 'post_id', 'object_id' );
Arr::change_key( $atts, 'meta_key', 'id' );
if ( empty( $atts['id'] ) ) {
return '';
}
$field_id = $atts['id'];
$object_id = $atts['object_id'];
unset( $atts['id'], $atts['object_id'] );
$value = $this->get_value( $field_id, $object_id, $atts );
$value = 'true' === $atts['render_shortcodes'] ? do_shortcode( $value ) : $value;
return $value;
}
Code file location:
meta-box/meta-box/inc/shortcode.php
Conclusion
Now that you’ve learned how to embed the Meta Box – WordPress Custom Fields Framework Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply