Guides
Display Custom Fields (Meta)
Custom meta fields may be used by developers. If you don't know how it works, read here more info https://wordpress.org/documentation/article/assign-custom-fields/.
Display Meta Value
PHP
<p>
<?php echo get_lzb_meta( 'control_meta_name' ); ?>
</p>
Use Conditions
PHP
if ( get_lzb_meta( 'control_meta_name' ) ) {
?>
<p>The value is True</p>
<?php
} else {
?>
<p>The value is False</p>
<?php
}
Work With Arrays
PHP
$repeater = get_lzb_meta( 'control_meta_name' );
foreach ( $repeater as $inner_control ) {
?>
<p><?php echo $inner_control; ?></p>
<?php
}
Work With Images
PHP
$image = get_lzb_meta( 'control_meta_name' );
if ( isset( $image['url'] ) ) : ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php endif; ?>
Work With Image ID
PHP
$image = get_lzb_meta( 'control_meta_name' );
if ( isset( $image['id'] ) ) {
echo wp_get_attachment_image( $image['id'], 'large');
}
get_lzb_meta
function
Fallback for Controls data always saved as encoded string and the function get_lzb_meta
make all necessary work to decode these strings.
It is required to use this method to retrieve meta data. But sometimes Lazy Blocks plugin is not in use, but meta is sill saved in the DB, then you will need to manually decode these meta before use.
This is a simple code, which will help you to decode and use meta strings:
<?php
// Retrieve raw meta value from DB.
$meta_val = get_post_meta( get_the_ID(), 'meta_name', true );
if ( $meta_val ) {
$meta_val = json_decode( rawurldecode( $meta_val ), true );
var_dump( $meta_val );
}
Previous ArticleInclude Lazy Blocks within theme or pluginNext ArticleCustom Post Type and Save in Meta control