Controls
Posts
Posts control creates a dynamic set of posts to search and select from and used to store a post ID value for the block. See examples below to use this control.
Control Settings
- Filter by Post Type – filters the selectable results via one or more post type. When left empty, all post types will be shown
- Filter by Taxonomy – filters the selectable results via one or more taxonomy term
- Output Format – specifies the returned value format. Choose from
Post ID
(integer) orPost Object
(WP_Post) - Multiple – select a single or multiple posts
Usage
PHP
$selected_post = get_post((int) $attributes['control_name']);
?>
<p>
<?php echo $selected_post->post_title; ?>
</p>
PHP + Multiple
<?php foreach( $attributes['control_name'] as $post_id ): ?>
<?php
$selected_post = get_post((int) $post_id);
?>
<p>
<?php echo $selected_post->post_title; ?>
</p>
<?php endforeach; ?>
PHP + Output Format as Post Object
<p>
<?php echo $attributes['control_name']->post_title; ?>
</p>
<p>
<?php echo $attributes['control_name']->post_type; ?>
</p>
To use Posts control with Handlebars, you have to set the
Output Format
option to Post Object
, because we don't have a specific Handlebars helper to work with WordPress posts.Handlebars
<p>
{{control_name.post_title}}
</p>
Handlebars + Multiple
{{#each control_name}}
<p>
{{this.post_title}}
</p>
{{/each}}
Post Meta
<p>
<?php echo get_lzb_meta( 'control_meta_name' ); ?>
</p>