---
title: "lzb/control_value"
description: "PHP filter `lzb/control_value` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/php-filters/lzb-control_value/"
lastUpdated: 2026-09-09
source: "php-filters/lzb-control_value.mdx"
---
# lzb/control_value

Converts what a control stored into what a template should see, which is how the Posts control turns saved IDs into post objects and how a custom control expands its own stored shape.

Three places call it, so a handler covers all of them at once. The block render callback runs it over every top-level control, `get_lzb_meta()` runs it over the control behind a meta name, and the Repeater control runs it over each inner control of each row. Every built-in control already hooks it at priority 5 through the base control class, matching on its own type, which means a handler at the default priority 10 sees the converted value rather than the raw stored one.

## Attributes

| Name            | Type       | Description                                                                                                                                                       |
| --------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$value`        | **Mixed**  | control value, already converted by the control's own handler                                                                                                     |
| `$control_data` | **Array**  | this control, with `type`, `name`, `label`, `default`, `child_of`, `placement`, `group`, `width`, `required`, `translate`, `save_in_meta` and `save_in_meta_name` |
| `$block_data`   | **Array**  | block data, the same array [lzb/block_data](https://www.lazyblocks.com/docs/php-filters/lzb-block_data/) returns                                                                            |
| `$context`      | **String** | `editor` or `frontend`                                                                                                                                            |

The whole chain is skipped when `$control_data` is empty, which happens in `get_lzb_meta()` for a meta name no control saves.

## Additional Filters

| Name                                          | Description                                    |
| --------------------------------------------- | ---------------------------------------------- |
| `lzb/control_value/control_type=CONTROL_TYPE` | filter value of specific control type          |
| `lzb/control_value/control_name=CONTROL_NAME` | filter value of specific control name          |
| `lzb/control_value/block_slug=BLOCK_SLUG`     | filter value of all controls of specific block |

`CONTROL_TYPE` is the type slug, so `lzb/control_value/control_type=image`. `CONTROL_NAME` is the control's `name`, the same string the template reads. `BLOCK_SLUG` is the full slug including the namespace, so `lzb/control_value/block_slug=lazyblock/recipe`. All three take the same four arguments as the main filter and run after it, in the order listed.

## Usage

```php title="PHP"
function my_lzb_control_value( $value, $control_data, $block_data, $context ) {
  // Show a placeholder image in the editor when the image control is empty,
  // so the preview does not collapse.
  if ( 'editor' !== $context || ! empty( $value ) ) {
    return $value;
  }

  return array(
    'id'  => 0,
    'url' => get_stylesheet_directory_uri() . '/img/placeholder.png',
    'alt' => '',
  );
}

add_filter( 'lzb/control_value/control_type=image', 'my_lzb_control_value', 10, 4 );
```

Return the shape the template expects. An Image control's value is an array with `id`, `url` and `alt`, and a template doing `{{image.url}}` prints nothing when it receives a bare string. Because the filter also runs inside `get_lzb_meta()`, a change made here shows up in every theme file that reads the meta, not only in the block.

To change the attribute's registered type rather than its value, use [lzb/prepare_block_attribute](https://www.lazyblocks.com/docs/php-filters/lzb-prepare_block_attribute/). To change the output of `get_lzb_meta()` after this filter has run, use [lzb/get_meta](https://www.lazyblocks.com/docs/php-filters/lzb-get_meta/).

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
