Menu
All plugins

Dynamic Comparison for Bricks

Dynamic Comparison for Bricks lets visitors pick items from a listing and compare them side by side. It adds three elements: a Compare Button for your query loop, a Compare Bar that shows what has been chosen, and a Comparison Table that reads your ACF fields.

Version: 0.5.3 · Requires: WordPress, Bricks Builder & PHP 7.4+. ACF is needed for custom field rows. · See the live demo

Please note: this is an early release. Stage & back up before using it on a live site.

What it does

  • Adds Compare Button, Compare Bar & Comparison Table to Bricks (General group).
  • Works with any public post type, with independent named groups so one page can host several comparisons.
  • Remembers the selection in the visitor browser (localStorage) and keeps several tabs in step.
  • Builds shareable comparison links that carry the chosen item IDs.
  • Shows a differences-only toggle and a table that scrolls sideways on narrow screens.

Quick start

  1. Make a Bricks query loop of your content, for example tours. Inside the loop card add a Compare Button. Choose the post type, a group name (for example tours) & the maximum number of items (2 to 6).
  2. Anywhere on the page add a Compare Bar with the same post type & group. It stays hidden until something is chosen. Optionally enter the address of a separate comparison page. If you leave it blank, the bar scrolls to a table on the same page.
  3. Add a Comparison Table with the same post type & group. List the ACF field names, separated by commas, and give friendly labels in the same order, for example demo_price,demo_duration and Price,Duration.

The post type and group must match on all three elements, otherwise they will not find each other.

The elements

Compare Button

Place it inside a query loop. It reads the current post, toggles it in the group & shows your add or remove label (aria-pressed tells assistive technology which state it is in). When the maximum is reached the Compare Bar shows a short limit message instead of a browser alert.

Compare Bar

Shows how many items are selected with Compare and Clear buttons. Compare goes to the table on this page or to the comparison page you set, with the selection added to the address.

Comparison Table

Needs at least two chosen items. Each column is headed by the item title & image, with one row per ACF field. Values from text, number, select, true/false (shown as Yes or No), post object, taxonomy and simple list fields are shown as plain text. A Show differences only checkbox hides rows where every item matches.

Sharing a comparison

Add ?dcfb_group=tours&dcfb_type=your_post_type&dcfb_ids=12,15,18 to the page address. The page picks the selection up on load and stores it for that visitor. Only public item IDs are copied into the link.

Styling

The plugin ships a few plain styles that are easy to override: .dcfb-add, .dcfb-bar, .dcfb-table, .dcfb-result, .dcfb-differences. The demo page keeps its stylesheet in the page, so you can copy it. The add button is aria-pressed="true" when chosen, which you can style.

Scripting

The script fires a dcfb:change event on the document whenever a selection changes. window.DCFB.refresh() re-reads every element, & window.DCFB.selected(group, type) returns the chosen IDs.

Security

  • The comparison data comes from a public REST endpoint, /wp-json/dcfb/v1/items. It returns published items of public post types only, up to six items & thirty fields per request.
  • It only returns ACF fields you list in the table element. It never returns arbitrary post meta.
  • Do not list private or sensitive ACF fields. Anything you list in a table is public.
  • All values are escaped & shown as text.

Limitations

  • Selections are stored in the visitor browser, so they are not shared between devices. Use a shared link for that.
  • Complex fields such as repeaters, flexible content & galleries are not shown.
  • The table layout is fixed: items as columns, fields as rows.
  • Test against your own Bricks, ACF & theme versions.

Changelog

  • 0.5.3 — the table no longer repeats the title as a row, and it scrolls sideways on narrow screens instead of widening the page.
  • 0.5.2 — fixed the Comparison Table never rendering, and the maximum-items message now appears in the Compare Bar instead of a browser alert.
  • 0.5.1 — renamed to Dynamic Comparison for Bricks. The shared trait no longer declares Bricks base-class properties.