Support Forum
Support › Meta Box Conditional Logic › Show meta box data on theme
I a not so good at php. I've purchased conditional mea box. But I am unable to show the meta box data on my theme.
Here is my function.php code:
add_filter( 'rwmb_meta_boxes', 'Brands_and_Products' );
function Brands_and_Products( $meta_boxes )
{
$meta_boxes[] = array(
'id' => 'brand_product',
'title' => 'Brands and Products',
'post_types' => array( 'post', 'page' ),
'context' => 'normal',
'priority' => 'high',
// Conditional Logic can be applied to Meta Box
// In this example: Show this Meta Box by default. Hide it when post format is aside
'hidden' => array( 'post_format', 'aside' ),
'fields' => array(
array(
'id' => 'brand',
'name' => 'Brand',
'desc' => 'Pick Your Favourite Brand',
'type' => 'select',
'options' => array(
'Samsung' => 'Samsung',
'Nokia' => 'Nokia',
'Symphone' => 'Symphone',
'Microsoft' => 'Microsoft',
'HTC' => 'HTC',
'Sony' => 'Sony',
'Huawei' => 'Huawei'
)
),
array(
'id' => 'Samsung_products',
'name' => 'Which Apple product that you love?',
'type' => 'radio',
'options' => array(
'Samsung galaxy S' => 'Samsung galaxy S',
'Samsung pop' => 'Samsung pop',
),
'hidden' => array( 'brand', '!=', 'Samsung' )
),
array(
'id' => 'Nokia_products',
'name' => 'Which Apple product that you love?',
'type' => 'radio',
'options' => array(
'Lumia' => 'Lumia',
'N Series' => 'N Series'
),
'hidden' => array( 'brand', '!=', 'Nokia' )
),
)
);
return $meta_boxes;
}
And here is the echo data on my theme :
<?php echo get_post_meta($post->ID, 'Brands_and_Products', true);?>
Can you help me out ?
Thanks in advance.
Hi qbangla,
To display data on frontend, simply follow this guide:
https://metabox.io/docs/get-meta-value/
Btw, in your case, Brands_and_Products
is a meta box, not holds any value, you can only get value of your field ids. For example:
// Brand
echo rwmb_meta( 'brand' );
// Samsumg Products
echo rwmb_meta( 'Samsung_products' );
// ...
Regards
Tan Nguyen