4.1 release and ACF field element conditions

Hello, I saw a forum post a couple weeks ago asking about conditionally showing/hiding elements based on whether an ACF field is empty or false, etc. Someone responded and said that this was a feature that would be rolling out in the 4.1 release. I didn’t see anything specific to ACF in the 4.1.x change log so I wanted to reach out and see if y’all could elaborate on that. Maybe I’m jumping the gun here, and it will all be revealed in the release notes, but if not, I would very much like to learn how to conditionally display ACF field content based on the value of the ACF field. I’ve been running into many scenarios in which I would like to use the Pro Builder’s ACF field dynamic content, but realize that I cannot because there is no way to test if the field is empty, or to test what value it returns. So I end up having to write up a shortcode to handle all the logic, and then put it in a text or raw content block.

Additionally, I’m hoping for more ACF integration into the dynamic content options:

  • Repeater field and Group fields
  • Fields that return arrays
  • Being able to get fields from options pages that have custom retrieval IDs (when setting up an ACF options page, there is an option for setting a custom ID to use when retrieving the field values… this is very useful when creating options pages for multiple custom post types and setting a retrieval ID of options_{post_type_slug} for each… then being able to assign the same field groups to multiple options pages and retrieve them with a dynamic retrieval ID, like on post type index pages for example.)

And a few other feature requests while I’m at it :wink:

  • Ultimately it would be awesome to have the option to use PHP functions in the element conditions for the most versatility.
  • for custom loopers, there is currently the option to use a custom WP_Query string, but I find that whenever I want to run a custom query that can’t be accomplished with the other looper options, it is usually because I need to do a more advanced meta query, or taxonomy query, which cannot be done using the query string. So it would be really nice to have the ability to enter a custom WP_Query object, allowing for the full capabilities of that class.
  • I would love to have the ability to create “global blocks” that did not require the Section/Row wrappers. It would be great to be able to create stand-alone div and element “global blocks” that could be edited/managed in one place, but update everywhere that they existed in the site.

Anyway. I’m loving all the new features in Pro. Keep up the great work. Cheers!

Hi @adaptifyDesigns,

Thanks for writing in about all this! A few thoughts I have to share in response to your comments and questions. Forgive some of it being more technical in nature, but from your message I gather you might be familiar with some of the more in-depth concepts I might touch on:

  • A more in depth ACF integration is planned including Looper Providers to work with ACF Repeater fields and nested repeaters. There will also be the ability to retrieve ACF fields from a term or global option (not just post data) We don’t have a timeframe on when this will be ready but it is a priority for us.
  • With Pro 4.1, using a string expression you can retrieve the contents of an ACF field and conditionally show an element if the value “is not” empty (just leave the second field blank.
  • If you hold ctrl/cmd when clicking + on a Section in the outline, it will let you choose a child element. The Div is now available as a direct child of a section. I know this doesn’t quite get you there, but at least it removes two additional elements when adding a Row and Column. We’ve been thinking of ways to further reduce the need to nest elements but there are some challenges to overcome first.
  • We won’t be able to add PHP function directly in the builder as this violates security best practices, but there are some some ways to work with PHP if you add custom code in a child theme or plugin and use the “Custom” looper type.
  • If you want to brave the source code, you’ll find there are a bunch of filters available (like cs_resolve_looper_provider) and classes you can extend like Cornerstone_Looper_Provider_Wp_Query which will allow very deep integrations with the looper system. It does require PHP and WordPress plugin development knowledge but there are some very powerful ways to expand the current capabilities.

Here’s a couple code example that I want to share as some food for thought.

/*
  Setup:
  1. Drag in a Looper List element
  2. Open the JSON and copy the content
  3. Switch the provider type to "Custom"
  4. Paste the JSON into the Params editor
  5. Set the hook to: "shuffle"
Result: You should see the items randomized on each page load
*/
add_filter( 'cs_looper_custom_shuffle', function( $result, $args, $element ) {
  shuffle( $args );
  return $args;
}, 10, 3);

Note: This second example will not work until the Pro 4.1.2 point release comes out. We’ve updated the Custom provider to detect if the array being returned is providing WP_Post objects. If that is true, it sets up the post to be used in Dynamic Content.

/*
  Setup:
  1. Set Looper Provider type to "Custom" with "get_posts" as the hook"
  2. Open the Params editor and enter:

{
  "offset": 10
}

Result: You can display posts with an entirely custom query 
*/
add_filter( 'cs_looper_custom_get_posts', function( $result, $args, $element ) {
  return get_posts( $args );
}, 10, 3);

Hopefully this helps give you an idea of where we are and where we’re going!

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.