Skip to content
Controls

Posts

Posts control lets you search and select WordPress posts, pages, or custom post types in your blocks.

Posts Control

Control Settings

  • Filter by Post Type - Limit selection to specific post types
  • Filter by Taxonomy - Filter posts by taxonomy terms
  • Output Format - Choose between Post ID or Post Object (WP_Post)
  • Multiple - Enable selection of multiple posts

Usage

Single Post Selection

PHP with Post ID
<?php
$selected_post = get_post((int) $attributes['control_name']);
if ($selected_post) {
    echo '<h2>' . esc_html($selected_post->post_title) . '</h2>';
}
?>
PHP with Post Object
<?php if ($attributes['control_name']) : ?>
    <h2><?php echo esc_html($attributes['control_name']->post_title); ?></h2>
    <div><?php echo esc_html($attributes['control_name']->post_type); ?></div>
<?php endif; ?>

Multiple Posts Selection

PHP with Post IDs
<?php
foreach ($attributes['control_name'] as $post_id) {
    $post = get_post((int) $post_id);
    if ($post) {
        echo '<h2>' . esc_html($post->post_title) . '</h2>';
    }
}
?>

Handlebars Usage

Set Output Format to Post Object when using Handlebars templates.

Single Post
<h2>{{control_name.post_title}}</h2>
Multiple Posts
{{#each control_name}}
  <h2>{{this.post_title}}</h2>
{{/each}}

Post Meta

Post Meta
<?php
$post_id = get_lzb_meta('control_meta_name');
$post = get_post((int) $post_id);
if ($post) {
    echo '<h2>' . esc_html($post->post_title) . '</h2>';
}
?>

Use Output Format as Post Object to access all post data directly without additional database queries.

Was this article helpful?