|

Advanced Cwicly Tutorial: The Unicorn Solution Has Arrived

advanced cwicly tutorial

Cwicly has become a very flexible and power solution that is built on the Site Editor and Gutenberg. It is a modern builder that allows you to work closely with CSS, HTML and other web technologies. In this video I do a walkthrough using several ACF field types and features, including a Repeater field and pulling data from a post relationship. Those are advanced features that most block plugins and even many page builders don’t support.

Video Version

Notes and Code Snippet

Here is the code to enable an ACF bi-directional post relationship. I understand that the ACF developers plan to include this in the plugin in the future. Be sure in the last line to change the name of the field to match your relationship field. The code comes from this post on the ACF website, which has some good information.

<?php 
function bidirectional_acf_update_value( $value, $post_id, $field  ) {
    
    // vars
    $field_name = $field['name'];
    $field_key = $field['key'];
    $global_name = 'is_updating_' . $field_name;
    
    
    // bail early if this filter was triggered from the update_field() function called within the loop below
    // - this prevents an inifinte loop
    if( !empty($GLOBALS[ $global_name ]) ) return $value;
    
    
    // set global variable to avoid inifite loop
    // - could also remove_filter() then add_filter() again, but this is simpler
    $GLOBALS[ $global_name ] = 1;
    
    
    // loop over selected posts and add this $post_id
    if( is_array($value) ) {
    
        foreach( $value as $post_id2 ) {
            
            // load existing related posts
            $value2 = get_field($field_name, $post_id2, false);
            
            
            // allow for selected posts to not contain a value
            if( empty($value2) ) {
                
                $value2 = array();
                
            }
            
            
            // bail early if the current $post_id is already found in selected post's $value2
            if( in_array($post_id, $value2) ) continue;
            
            
            // append the current $post_id to the selected post's 'related_posts' value
            $value2[] = $post_id;
            
            
            // update the selected post's value (use field's key for performance)
            update_field($field_key, $value2, $post_id2);
            
        }
    
    }
    
    
    // find posts which have been removed
    $old_value = get_field($field_name, $post_id, false);
    
    if( is_array($old_value) ) {
        
        foreach( $old_value as $post_id2 ) {
            
            // bail early if this value has not been removed
            if( is_array($value) && in_array($post_id2, $value) ) continue;
            
            
            // load existing related posts
            $value2 = get_field($field_name, $post_id2, false);
            
            
            // bail early if no value
            if( empty($value2) ) continue;
            
            
            // find the position of $post_id within $value2 so we can remove it
            $pos = array_search($post_id, $value2);
            
            
            // remove
            unset( $value2[ $pos] );
            
            
            // update the un-selected post's value (use field's key for performance)
            update_field($field_key, $value2, $post_id2);
            
        }
        
    }
    
    
    // reset global varibale to allow this filter to function as per normal
    $GLOBALS[ $global_name ] = 0;
    
    
    // return
    return $value;
    
}
add_filter('acf/update_value/name=book_author_relationship', 'bidirectional_acf_update_value', 10, 3);

Discussion

There are different market segments, even within Gutenberg. Some focus on templates, while others focus on a middle ground where the blocks are flexible and powerful enough for most sites, but easy enough for clients. However, there is also the need for sites with advanced functionality and up to now people needed to resort to a page builder if they were reaching beyond what was possible in the Site Editor.

However, since its release Cwicly has steadily improved and today it is the most capable Gutenberg solution. Cwicly has a learning curve and it is not a tool for clients, but for advanced sites that need a lot of dynamic data features I’d say that Cwicly has arrived. Even though it is still getting big new features, it is mature and stable enough for production use.

The only Gutenberg solution that is even close for advanced dynamic data features is Greenshift, and it has its nice qualities and is easier to use, but Greenshift has grown by accretion over time and its user interface is not as advanced or as coherent as Cwicly’s. I think the Greenshift developers are refactoring the UI, but the trade off for ease of use is that it does not have the same level of advanced features.

Advanced builders don’t appeal to everyone. Many people prefer something simpler and quicker to use, but if you have been using Oxygen or Bricks and you want to move over to Gutenberg then Cwicly is the way to go. I fully endorse Cwicly as one of the best site builder solutions available for WordPress today.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *