Hello!
I am working on a project where the field called “featured” for one of the post types is of boolean type (that is, it can be turned on and off). If I use the dynamic data query to display the field content, it naturally returns 0 and 1.
How could it be solved that if a value of 1 is returned, then the field should return the text “Featured” and if it is 0, it should return an empty string element.
I’ve tried searching online and Bricks Builder related materials, but I haven’t found anything useful.
I take care of this:
if ({some_field_data} == 1) {echo: “Featured” } else {echo: “”}
Thanks in advance for the ideas and information!
Zoltán
What kind of field, ACF, Metabox, WP Custom Field? Is it a toggle, radio, checkbox?
If you set a checkbox in ACF you can set label to Featured and return that.
If it’s just your own field, or can only return 0/1 you could add a basic text element and set conditions: if {cf_featured} is 0 (or 1) to display (or hide).
Hello!
Thanks for the reply. I don’t know what kind of field it is. The extension is called Essential Real estate
https://wordpress.org/plugins/essential-real-estate/
I made two screenshots, one of which switches the Featured setting in the property list (on and off).
The other is to display the fields after querying the property list. Here I ran into a problem with the Features field, because it returns either 0 or 1 value (off or on).
Here, I would like to resolve that if the returned value should return an empty string (or not return any results, not even the field itself), if 1, then the text “Featured”.
I hope I have described it clearly.
Thank you
Zoltán
As I said, create a basic text element, then add a condition. Condition = Dynamic data, {cf_real_estate_property_featured}, =, 1
It will only display if 1 (or true) is returned.
Thanks for the reply. I finally managed to solve it. I placed the simple code below in the functions.php file of the child theme.
So the
call: {echo:conditionally_featured_text()}
dynamic data returns text instead of number.
// Essential Real Estate plugin - Bricks: If the property is highlighted, it returns "Featured" text, otherwise "Normal" text.
// call: {echo:conditionally_featured_text()}
function conditionally_featured_text() {
$field_featured = bricks_render_dynamic_data( '{cf_real_estate_property_featured}' );
// You can get more parameters as you like
if ( $field_featured == 1 ) {
return 'Featured';
} else {
return 'Normal ';
}
}
1 Like