Meta box Field Value

The Meta Box plugin integration with Conditional Blocks allows you to control the visibility of WordPress content blocks based on the values of Meta Box fields. This powerful feature enables you to create dynamic, conditional content that responds to user input or custom fields within your WordPress site.

Requirements

How to Control Block Visibility Based on a Meta Box Field

Using Meta Box fields to manage the visibility of blocks in the WordPress Block Editor is straightforward. This guide will walk you through the process of setting up Meta Box fields and using them to control block visibility.

1. Creating Fields in Meta Box

Firstly, you need to register your custom fields within Meta Box. There’s two ways you can do it:

Our example code generates a field group called “Location” and a meta field for the “City Name“. These fields which will apear on pages and posts. You can of course be more creative and use custom post types.

Below you’ll see our example snippet running in WordPress. If you choose to use the Meta Box builder you don’t have to run a snippet.

Screenshot of Meta Box code being added to WordPress

2. Setting the Field Values in a WordPress Post

When editing a post in WordPress, scroll down to the Meta Box fields section and set the values for each field. For instance, if you’re adding event details, you would input the date, location, and organizer’s name.

Example screenshot with an arrow to meta fields in WordPress post editor.

3. Changing the Visibility of Content with Meta Box Value

After setting up your fields and inputting values, you can control the visibility of blocks in your post:

Screenshot of using the Conditional Builder in WordPress to add Meta Box conditions.
  1. Create a block or design pattern in the WordPress editor.
  2. Click on the block and navigate to the Conditional Blocks section in the sidebar, then click Edit Visibility.
  3. In the conditions list, select “Meta Box Field Value“.
  4. Choose the Meta Box field you want to use for the condition.
  5. Set the operator to define how the field value will be checked.
  6. Enter the expected value for the field.
  7. Preview the post to ensure the block content displays correctly based on the condition.

For example, we are displaying a block if the post meta city_name equals Perth or not.

This is a very simplistc example of using meta data. However, you can be as creative as you’d like. The common use-cases for meta data is to create custom post types, and use custom templates to fit your data.

You can use Conditional Blocks on Full Site Editing template parts, or re-useable blocks as well.

Frequently Asked Questions

Which Value Operators Are Available?


The following operators are available to check the value of a Meta Box field:

  • Has any value (not_empty)
  • No value (empty)
  • Equal to (equal)
  • Not equal to (not_equal)
  • Contains (contains)
  • Does not contain (not_contains)
  • Greater than (greater_than)
  • Less than (less_than)
  • Greater than or equal to (greater_than_or_equal_to)
  • Less than or equal to (less_than_or_equal_to)

Does This Work with Other Custom Field Plugins?

The Meta Box integration is specifically designed to work with the Meta Box plugin using its native functions, such as rwmb_meta(). However, Conditional Blocks also offers a “Post Meta (custom fields)” condition that can work with custom fields from other plugins, provided you know the field keys.

By following these steps, you can leverage the Meta Box plugin’s custom fields to create dynamic, conditional content in your WordPress site using Conditional Blocks Pro.

Was this page helpful?