Displaying fields with code
If you're a developer and familiar with changing template file with PHP code, you can use Meta Box helper functions to display fields:
rwmb_get_value()
: to get a field value as a variablerwmb_the_value()
: to display a field
In addition, we also provide rwmb_meta()
function, which is a wrapper of the 2 functions above which:
- Returns the HTML output for rich-content fields:
map
,osm
, andoembed
, same asrwmb_the_value()
, - Returns the same value as
rwmb_get_value()
for other field types.
Now open your template file for the single event content. Usually, it's template-parts/content.php
, single-event.php
or single.php
file, depending on your theme structure. Then add the following code below the content area:
<?php
/**
* Template part for displaying single post content
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header>
<div class="entry-content">
<?php the_content(); ?>
<p>
<strong>Date and time:</strong> <?php rwmb_the_value( 'datetime' ) ?>
</p>
<p>
<strong>Location:</strong> <?php rwmb_the_value( 'location' ) ?>
</p>
<p>
<strong>Map:</strong>
</p>
<?php rwmb_the_value( 'map' ) ?>
</div>
</article>
Block themes
For block themes, everything is blocks and there's no PHP template files. In that case, please use the MB Views extension.
All functions accept the following parameters:
Name | Description |
---|---|
$field_id | The field ID. Required. |
$args | Extra arguments for some field types (image, file, etc.). Can be array or a string in format param1=value1¶m2=value2 . See more details in field types. Optional. |
$object_id | Object ID that custom fields are got from. Optional. If not present, the current post ID is used. |
$echo | Echo the HTML output (true - default) or return it (false ). Applied only for rwmb_the_value() function. |