WIP: Component with both Repeater Property and Query Loop as data sources

With the new Repeater Property in Bricks 2.5, I would like to build reusable components that support two alternative data sources:

  • Manual: Populate the component manually using the Repeater Property.

  • Dynamic: Populate the same component using data from a Query Loop, for example from a Custom Post Type.

Typical use cases would be card grids, accordions or sliders.

Ideally, I would like to choose the data source individually for each component instance without duplicating the element structure, Query Loops or dynamic data mapping.

One possible approach would be to populate the Repeater Property dynamically with the results of a Query Loop instead of entering the values manually. Is this possible in Bricks 2.5?

If not, is there another recommended way to achieve this?

The goal is to maintain a single component structure and field mapping, regardless of the data source.

How would you approach this?

Bricks 2.5 beta 2 doesn’t have a built-in option to populate a Repeater Property from a Posts Query. The Repeater Property works the other way around. It supplies rows to an Array Query Loop inside the component.

I tested this with a card grid using one component, one Array Query Loop, and one field mapping. Each instance has a Data source dropdown with two options:

  • Manual uses rows entered in the Repeater Property.
  • Latest products uses a small PHP adapter that fetches WooCommerce products and passes them to the same loop. You could use the same approach with another custom post type.

Both sources provide title and summary, so the heading and description only need to be connected once. The adapter supplies the dynamic rows when the component renders, and the manual entries stay available if you switch back.

This worked with two instances on the same page, one manual and one dynamic. Only the dynamic source needs custom PHP.

<?php

/**

 * Plugin Name: Classic Lab – Card Grid Source

 * Description: Supplies catalog rows for the local two-source card grid example.

 */

defined( 'ABSPATH' ) || exit;

add_filter( 'bricks/query/prepare_query_vars_from_settings', function ( $settings ) {

	if ( ! isset( $settings['query']['arrayItems'] )

		|| 'classic-lab-catalog' !== ( $settings['_cssClasses'] ?? '' ) ) {

		return $settings;

	}

	$rows = [];

	if ( function_exists( 'wc_get_products' ) ) {

		$products = wc_get_products( [

			'status'  => 'publish',

			'limit'   => 3,

			'orderby' => 'date',

			'order'   => 'DESC',

			'tax_query' => [

				[

					'taxonomy' => 'product_visibility',

					'field'    => 'slug',

					'terms'    => [ 'exclude-from-catalog' ],

					'operator' => 'NOT IN',

				],

			],

		] );

		foreach ( $products as $product ) {

			$description = $product->get_short_description() ?: $product->get_description();

			$rows[] = [

				'id'      => 'product-' . $product->get_id(),

				'title'   => esc_html( $product->get_name() ),

				'summary' => esc_html( wp_trim_words( wp_strip_all_tags( strip_shortcodes( $description ) ), 22 ) ),

			];

		}

	}

	$settings['query']['arrayItems'] = $rows;

	return $settings;

} );

Hi @HExSM, Bricks 2.5 beta 2 doesn’t have a built-in way to choose between manual repeater rows and a Posts query for each instance of the same component while keeping one loop and one set of field connections.

To support this natively, the component author would need a way to define which sources a loop accepts and how each source fills the same fields. For example, a card heading could stay connected to a Title field. In manual mode, Title would come from the repeater row. In query mode, it would come from the current post’s title. Once the author sets that up, each instance could choose its source and reuse the same card layout.

I’d be interested to hear from others who need this too. What component are you building, and which data sources would you want to switch between? Concrete examples would help us understand how common this need is.

Best regards,
Matej

First of all, thank you @nudinlubis for taking the time to test this and provide a working solution. I really appreciate it!

Your approach demonstrates the concept very well. However, I would love to have a more flexible solution that doesn’t require custom PHP for different data sources.

@Matej, thanks for your response! Here are some practical use cases I have in mind:

  • Accordion / FAQ component: Manually entered FAQs for a specific landing page or dynamically retrieved FAQs from a centralized FAQ CPT, filtered by category or relationship.

  • Card grid component: Manually curated cards or dynamically generated cards from different CPTs, such as services, products, projects, or team members.

  • Pricing card component: Manually configured pricing plans or dynamically retrieved plans from a dedicated CPT or WooCommerce products.

  • Slider component: Manually selected content or dynamically retrieved testimonials, references, or featured products.

In all these cases, I want to maintain a single component with the same structure, styling, and internal field connections, regardless of the data source.

Possible implementation

What if the existing Repeater Property could be extended with an optional “Query Loop” toggle, similar to the existing Query Loop functionality in Bricks?

  • Query Loop disabled: The Repeater Property works exactly as it does today. Users manually add and populate individual repeater items.

  • Query Loop enabled: Users configure a query using the existing Bricks query controls. Instead of adding individual items, they configure the repeater fields only once using the Dynamic Data Picker.

For example, for a card grid component, the repeater fields could be populated as follows:

  • Title → Post Title

  • Description → Custom Field

  • Image → Featured Image

  • Link → Post URL

Bricks would then automatically generate one repeater item for each query result, resolving the dynamic data in the context of that result.

The Dynamic Data Picker is already visible in the repeater fields, although it doesn’t seem to be functional there in the current beta. Perhaps this existing interface could be used for the field mapping without introducing a separate mapping UI.

Ideally, both the query and the field mapping could be configured at component instance level. This would allow the same card grid component to display services on one page, projects on another, and manually curated content on a third — without modifying the main component.

Why this would be valuable

  • Truly reusable, data-source-independent components.

  • No need to maintain separate manual and dynamic versions of the same component.

  • Centralized maintenance of structure and styling.

  • Flexibility to use different CPTs with different custom field structures.

  • No need for custom PHP adapters.

I think this would be a natural extension of the existing Repeater Property, combining three powerful features that Bricks already provides: Repeater Properties, Query Loops, and Dynamic Data.

The component would define how the content is displayed, while each component instance would define where the content comes from.

Would something like this be feasible within the current component architecture?

Hi @HExSM,

The accordion example helped me understand why the extra wrapper matters. If I understand you correctly, you’d like the person editing a component instance to open its Repeater Property and choose between two data sources:

  • Manual entries would show the usual repeater rows and Add item button. For an FAQ accordion, the editor would enter each question and answer directly.
  • Query loop would let the editor select the FAQ post type, apply filters, and map the repeater fields once. For example, Question could use the post title and Answer could use a custom field. Each matching post would then supply one accordion item.

The accordion item would stay directly under the accordion root. Its heading and content would stay connected to Question and Answer, regardless of which source that instance uses. Switching back to Manual entries would restore the rows the editor had entered.

Does that match how you’d expect to edit an instance?

Best regards,
Matej

Hi @Matej,

Yes, that’s exactly what I had in mind!

Being able to configure both the query and the field mapping at the component instance level, while keeping the internal structure and field connections unchanged, is the key aspect.

Preserving the manually entered rows when switching between data sources would be a great addition as well.

This would make components truly data-source-independent without requiring nested components, redundant properties, separate Query Loops or additional HTML wrappers.

Thanks for taking the time to understand the use case!

Perfect, thanks for confirming :slight_smile: I’ve added this to our internal tracker as an improvement idea.

Thank you,
Matej