Checking if Repeater/Cloneable Meta Fields Are Empty in Bricks

Plugins like ACF, Meta Box and JetEngine enable us to register custom meta for posts in WordPress that are repeating/cloneable. Ex.: A Technology field that has say, Technology Name and Technology Age sub fields.

There could be times when you want an element say, a Bricks Section that contains such repeater fields to be rendered only if there is at least one row in the field i.e., if the field is populated with at least 1 set of sub field values.

We can create a custom function that returns the count of array items and use this with the Dynamic data condition in Bricks to ensure that the Section gets output only if at least one row of data is filled in.

Add this in child theme‘s functions.php or a code snippets plugin:

function bl_get_repeater_count( $field_name ) {
	return count( get_post_meta( get_the_ID(), $field_name ) );
}

and apply a condition like this:

{echo:bl_get_repeater_count(technologies)}

Replace technologies with the name/ID of your repeating custom field.

Instant access to 390+ Bricks code tutorials with BricksLabs Pro

7 comments

Leave your comment