CMB2 is very powerful and setting up fields in code prevents accidental changes. get_post_meta() is used on the front end. Neat and fast.
Following on from my last post where I used WordPress API functions instead of ACF’s get_field(), I tried out CMB2. Bill Erickson mentioned that he prefers CMB2 over ACF for most circumstances.
I installed the CMB2 plugin and worked through the docs to set up the meta boxes for the same fields as I used in the Belgrove Bouncing Castles site.
I put the fields in groups like I had done for the ACF fields. In CMB2 this had the surprising consequence where the values of the fields within each group were in a single entry in the post_meta table.
Here are the fields as set up in ACF Pro:
Set up ACF Pro fields in CMB2
The CMB2 setup code is quite straightforward:
The meta boxes are displayed similarly to the ACF Pro fields though the ACF groups are displayed in tabs, which is neater and more compact.
Display the CMB2 data
Rendering the data on the front end was a tiny bit easier than earlier because the url of the full size image is in the database.
CMB2 in my future?
Although ACF is very easy to set up, the negative impact on the front end is a concern. I may consider trying to use CMB2 as a site maintainer cannot accidentally change the fields through the admin area and it is faster.
hi,
Good article. Could you explain what is the negative impact on the front end when using ACF?
Thank you!
See my earlier post: https://www.damiencarbery.com/2017/10/disable-acf-on-frontend-reduced-db-queries/ I read a post by Bill Erickson (https://www.billerickson.net/code/disable-acf-frontend/) so I decided to use WordPress functions instead of ACF’s get_field(). It reduced database queries by 36% (58 queries down to 37).