Skip Navigation

[Resolved] Hiding a div based on a either/or conditional

This thread is resolved. Here is a description of the problem and solution.

Problem:

Get custom field value in PHP codes.

Solution:

You can try WordPress function get_post_meta(), for example:

https://toolset.com/forums/topic/hiding-a-div-based-on-a-either-or-conditional/#post-1849457

Relevant Documentation:

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by chrisC-25 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1849211

I want to hide a div based on whether it has certain fields are not empty but this needs to be either/or since there will be times when one field is filled in but another is not. I had a solution here:
https://toolset.com/forums/topic/hiding-a-complete-div-if-all-conditionals-are-met/

But now I want to add another field in to the code.

Here is code

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_filter( 'ddl_render_row_start', function( $markup, $args, $row, $renderer ){
 global $post;
  
  
$is_empty = false;
  
if($args['additionalCssClasses']=='pop-culture-box') {
  	 $value = get_post_meta($post->ID,'wpcf-pop-culture-spotify-playlists-link',true);
     if(empty($value)){
       	$args['additionalCssClasses'] = "hidden";
       $is_empty = true;
     }
}
  
        if( $is_empty ){
            ob_start();?>
               <<?php echo $args['tag']; ?> class="hidden"<?php if ($args['cssId']) { echo ' id="' . $args['cssId'] . '"'; } ?> >
  
                
            <?php
        $markup = ob_get_clean();
        }
 
        return $markup;
}, 99, 4 );

I want to add wpcf-video-2-id as another option. If wpcf-video-2-id is not empty it should show the div. How do I add that as an OR option to this line:
$value = get_post_meta($post->ID,'wpcf-pop-culture-spotify-playlists-link',true);

Thanks

#1849457

Hello,

Please try to modify these lines from:

...
     if(empty($value)){
...

With:

...
	 $video_2_id = get_post_meta($post->ID,'wpcf-video-2-id',true);
     if(empty($value) && empty($video_2_id)){
...
#1849825

My issue is resolved now. Thank you!