Viewing 12 replies - 1 through 12 (of 12 total)
  • I have this exact same request. Using the Divi Theme Builder, I want to display a row only if a custom field in the post has a value. In my case an image URL.

    I’m using Advanced Custom Fields to create the custom field.

    Thanks muchly.

    Hello,
    Looking for the same thing !

    I got it to work

    // Divi module visibility
    // with field num_tel
    function my_condition() {
    	global $post;
    	
    	$r = false;
    	if ( function_exists('get_field') ) {
    		if ( get_field('num_tel') ) {
    			if ( !empty(get_field('num_tel')) ) {
    				$r = true;
    			}
    		}
    	}
    	
    	return $r;
    }
    Thread Starter Azzam Daaboul

    (@azzamdaaboul)

    Hi Doobeedoo,

    Is it for ACF? I am using another plugin and it didn’t wrok with me.

    Thanks

    Yes, this is for ACF

    For the plugin you use, the functions are written in their documentation
    https://www.ads-software.com/plugins/custom-post-types/

    It is get_custom_field($field_id, $post_id)

    You can try something like this:

    function my_condition() {
    	wp_reset_postdata();
    	global $post;
    	
    	$r = false;
    	if ( function_exists('get_custom_field') ) {
    		if ( !empty(get_custom_field('YOUR_FIELD')) ) {
    			$r = true;
    		}
    	}
    	
    	return $r;
    }

    @doobeedoo Do I put that ACF php code in functions.php? Would you also tell me what code goes in the content visibility field in the advanced tab of Divi Builder? I’m having a need to hide a Divi Section in the header of my website because it’s only for Occasional Site wide Alerts. I’m using ACF with Divi Builder and simple text message in a divi section. I understand that I need to replace all instances of num_tel with my field name.

    // Divi module visibility
    // with field num_tel
    function my_condition() {
    	global $post;
    	
    	$r = false;
    	if ( function_exists('get_field') ) {
    		if ( get_field('num_tel') ) {
    			if ( !empty(get_field('num_tel')) ) {
    				$r = true;
    			}
    		}
    	}
    	
    	return $r;
    }

    Yes this code goes into functions.php
    Code to put in the Divi module visibility condition is the name of the function, here it’s my_condition()
    You can change this name

    @doobeedoo I implemented the code but it just removes the entire Divi Builder Section completely. I implemented a custom post type using CPT UI plugin and named it Site Alert but I created a field using the name “alerttext” that is just a simple ACF text field. All I want to do is show the alert if there is text in the ACF text field named alerttext and if the client removes the text, I just want the Site Alert to disappear so the site looks normal again. I used a Divi Global header and I have the Site Alert in it’s own section and the ACF shortcode pasted in a Divi text element. This is very annoying, wish there were Boolean examples that work for my scenario. I don’t know what I’m doing wrong. It’s been many hours and I still cannot figure it out. I’m never using Divi Builder again. It’s terrible.

    @whyknott This is not related to Divi
    Divi is great
    This is related to this plugin “Content Visibility for Divi Builder” and your understanding of WordPress, PHP, and your functions.php file

    I agree that the author of this plugin “Content Visibility for Divi Builder” could give more boolean examples, it took me some time to find the solution for my case too

    It’s not possible to help your case further without seeing your site, as every site is different

    If I were you I would note this need and other needs and hire a developer to help you with technical things

    Cheers

    Hi, I use it this way and it works for me.

    function_exists('get_field') && get_field('cjeu_cnationalleg') != ''

    hi,
    I’m using the ACF repeater
    repeater name: packages
    subfield name is: plan_name
    how can I use this code to hide a row if this field is empty?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Hide custom field when it’s empty’ is closed to new replies.