Powered by LUIT.nl - Constant beta
peterluit_vrijstaand

Conditional placement of ‘things’ based on field content

Conditional placement of ‘things’ based on field content

In the Beaver Builder Knowledge base there is a little but powerful routine which makes it possible to show or hide a row or a module based on the content of a field connector. That is the base of the power of conditional database publishing within WordPress. Website strip-down of orange-exhibition management.

The base of ‘getting things done’ is Beaver Themer, Pods and the Pods Beaver Themer Add-on

Orange-exhibition management is a dutch agency for exhibitions in the foodsector in amongst others Dubai, China, Indonesia and Canada. The main content is about detailed information around exhibitions at various locations and dates together with the possibility to reserve exhibition space for exhibitors. It is a business-to-business website, so no booking for visitors.

When we started the first setup was very simple. Each exhibition was ‘just a page’ (without a fixed content structure) and each page could be accessed through the menu. But as ‘things’ developed yhe number of exhibitions increaded and with that also the need for some more structure in managing past, present and future exhibitions. That is where a database approach ‘came in’, with custom post types and custom fields. Each exhibition (we called the CPT base ‘event’) would get a set of custom fields to get the job done. For making the right setup of fields, we needed to do an in-depth examination of the content which needed to be accessible by individual fields. We created two fields we used for our first conditional approach. Two fields were created for our conditional approach:

  • more information link
  • booking form link

Conditional

In our non-conditional approach we made these field ‘required’, since the button would have to go ‘somewhere’. In our conditional approach we had to deselect ‘required’, since we want to make a condition based on the fieldvalue itself.

Without conditions these buttons would ‘always be there’, since we created the single custom post temple in Themer. However there are a couple of situations in which our customer did not want visitors to be able to choose one or both buttons:

  • In case of a past event, booking should not be possible anymore
  • In case of a future event, where details are not there yet to either make a booking or to get more in-depth information

The simple routine in the Beaver Themer knowledge base just gives the possibility to either display or not to display a row or module based on the specific field in that row or module. In our case the URL in the button setup is the only conditional field we could define, there is nothing else.

Copy the routine and insert it into your functions.php file in your childtheme

Do not select ‘Required’ to be able to leave the field empty

Until now we cannot yet make conditions based on other fieldvalues outside the row or module. And we cannot make any AND/OR combinations yet to combine conditions. But with the little routine, the beginning is there. In the BB facebook group Chinmoy Kumar Paul seems to be developing a more advanced fields conditions plugin to show or hide modules or rows based on multiple conditions. That would be of great value.

We created a simple screenshot on how we think about a more interactive approach to set ‘field conditions‘ with Themer. We are thinking about the areas on which such field conditions could work. Would it be useful to do this for either theme layouts, parts, rows and modules?

Not all modules are very easy to configure with ‘just a simple’ field condition. If you use the text editor module, have a look at ‘conditional shortcodes‘ to get it done the right way. (This link thanks to Bernhard Gronau).

If (for any reason) the address of the event location is not known (yet), in our case we inserted the following conditional in the text editor:

[wpbb-if post:pods_display field='street_number'][wpbb post:pods_display field='street_number'][/wpbb-if]

Powerful

Field conditions will be for sure add a powerful value to real database publishing with WordPress.

4 Comments

  1. Athlone on October 29, 2017 at 13:59

    Extremely useful, thanks Peter. I’ve started to work with more complex setups in Themer and it’s quite easy to get things done once you get the gist of it. This function extends it further and I’m quite excited to implement it. Thanks for sharing.

    • Peter Luit on October 29, 2017 at 17:14

      Thanks for your comment Athione. I hope the BB team will jump into this.

      Peter

  2. Robert on November 3, 2017 at 01:16

    I’m intending on using Woocommerce Memberships to provide access to elements on a given page, if the person has said access. For instance, if they don’t, it would show a place holder, but if they do, it would show a video or carousel of videos. If I use pods and conditionals, would it be possible to show/hide rows based on member access? Not sure if Pods has the capability to tie into Woocommerce Memberships. Otherwise how I would normally do this would be to hard code php if statements to check for access and then forego having to use BB at all and just hook into content locations to display things.

    • Peter Luit on November 3, 2017 at 14:25

      Well, displaying a row just can depend on a fieldvalue used in that row. Themer supports WooCommerce, but I don’t know if it support (all or any) add-ons, like in your case WC Memberships.

Leave a Comment