'How to hide when ACF relationship field is empty on Elementor without using a plugin
I have a custom post type called "Product" and I have ACF relationship field called meta_product_hands_on_review to pull related review posts in the product.
I would like to hide a link "Read Hands On Review" in a product box, if the relationship field is empty. Product box screenshot
I tried using a dynamic condition plugin but they don't support relationship field for dynamic tags.. Elementor admin screen with the plugin
It would be great if I can achieve this without using any plugins! I use code snippet and if anyone can help me with custom php code that I can add to my code snippet, it would be amazing!
Solution 1:[1]
You would use an if statement to check whether the field is empty or not. If the field is empty, it will not show anything. If the field has data, put what you want to show in the else section of the conditional statement.
$acfField = get_field( 'meta_product_hands_on_review' );
if ($acfField) {
return;
} else {
// Show the field here
}
Here is more about hiding fields with ACF: https://www.advancedcustomfields.com/resources/hiding-empty-fields/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JayDev95 |
