It took me some time to get my head around this.
Having two separate content sources, Bricks and WP.
Bu now that I understand the concept, itās kindof pretty cool. You can simply put create a post template and either put a Content Element in with WP as source or with Bricks as source. Or you can do BOTH. In which case either one will be rendered, whichever one has data. It becomes messy when BOTH have data.
For that, I have created a display condition which will allow you to select which one will be rendered. This allows you to filter for Bricks content. You do not need a filter for WP content because surely, you will want to display the WP stuff if there is no Bricks content.
On a side note, the dual content is cool because it allows you to create a Bricks content post and IN THAT POST add the content element with WP source, meaning you can insert the WP post data into the Bricks post. Meaning you could create a skeleton Bricks post which only Admins can change and your editors and contributors can change the WP content within it.
Anyhow, hereās a condition snipped that youād have to add to your functions.php file or use any code snippet plugin. You could even add this as - probably (I have not tested this) - into your header as a Bricks code element.
/**
Snippet Name: Check for Bricksbuilder.op post data
@author Ingo Ratsdorf
@link https://ingo.envirology.co.nz
@version 1.0.0
Description: Adds a condition condition in Bricks Builder based on whether
there is Bricksbuilder content available or not.
Tested with 2.2RC.
Usage:
Add this snippet to your themeās functions.php file or a custom code snippet plugin.
*/
class Has_bricksbuilder_content_condition {
public function __construct() {
add_action('init', array($this, 'init'));
}
public function init() {
// Add the new visibility condition to Bricks Builder
add_filter('bricks/conditions/options', array($this, 'add_bricksbuilder_content_condition'));
// Check the condition result
add_filter('bricks/conditions/result', array($this, 'check_bricksbuilder_content_condition'), 10, 3);
}
public function add_bricksbuilder_content_condition($options) {
$options[] = [
'key' => 'has_bricksbuilder_content',
'label' => esc_html__('Has Bricks Content', 'bricks'),
'group' => 'post',
'compare' => [
'type' => 'select',
'options' => [
'Yes' => esc_html__('Yes', 'bricks'),
'No' => esc_html__('No', 'bricks'),
],
]
];
return $options;
}
public function check_bricksbuilder_content_condition($result, $condition_key, $condition) {
// Only handle the custom 'has_bricksbuilder_content' condition
if ($condition_key !== 'has_bricksbuilder_content') {
return $result;
}
// Determine if the current device is mobile or desktop
$current_device = wp_is_mobile() ? 'mobile' : 'desktop';
// Get the selected condition values from Bricks or use default 'Yes'
$compare = isset($condition['compare']) ? $condition['compare'] : 'Yes';
// Try and get Bricksbuilder data for post
$bricks_data = \Bricks\Database::get_data( get_the_ID(), 'content' );
if ($compare === 'Yes') {
return $bricks_data ? true : false;
} elseif ($compare === 'No') {
return $bricks_data ? false : true;
}
return $result;
}
}
new Has_bricksbuilder_content_condition();