Skip Navigation

[Resolved] Output of notice when view field has no value

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

Problem:

Conditional display on custom fields which have empty lines.

Solution:

You can try below custom shortcode:

https://toolset.com/forums/topic/output-of-notice-when-view-field-has-no-value/page/3/#post-2207787

Relevant Documentation:

This support ticket is created 3 years, 6 months 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 31 replies, has 3 voices.

Last updated by martinG-11 3 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2207787

I have done below modifications in your website:
1) Modify the PHP codes as below:

add_shortcode('remove-empty-lines', function($atts, $content){
  	$atts = shortcode_atts( array(
        'field' => 'wpcf-issue',
    ), $atts );
  	$res = '';
  	$value = '';
  	if(isset($atts['field'])){
    	$value = get_post_meta(get_the_ID(), $atts['field'], true);
      	$value = trim($value);
    }
  	if(empty($value)){
      $res = do_shortcode($content);
    }
    return $res;
});

2) Modify the shortcode in content template as below:
[remove-empty-lines]nicht verfügbar [/remove-empty-lines]

Please test again, check if it is fixed, have a nice day

#2207837

My issue is resolved now. Thank you!