A Cozmoslabs Product
Documentation / Developer Knowledge Base / Shortcodes / Check if multiple fields are empty shortcode

Check if multiple fields are empty shortcode

This function adds a shortcode that checks if multiple fields are empty.

Shortcode:

[multiple_empty_user_fields fields=”{{meta_first_name}},{{meta_last_name}}”]
* Show only if at least one meta is not empty. *
[/multiple_empty_user_fields]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Check if multiple fields are empty shortcode. Tags: shortcode, multiple, empty
 * Usage:
 * [multiple_empty_user_fields fields="{{meta_first_name}},{{meta_last_name}}"]
 * Show only if at least one meta is not empty.
 * [/multiple_empty_user_fields]
 */
add_shortcode( 'multiple_empty_user_fields', 'wppb_multiple_fields_empty' );
function wppb_multiple_fields_empty( $atts, $content ) {
   extract(
      shortcode_atts( array( 'fields' => '' ), $atts )
   );
   $fields = explode( ',', $atts['fields'] );
 
   foreach ( $fields as $value ) {
      $value = trim( $value );
      if ( ! empty( $value ) ) {
         return $content;
      }
   }
   return '';
}

Profile Builder Pro

Create beautiful front-end registration and profile forms with custom fields. Setup member directories, custom redirects, cutomize user emails & more using the all in one user management plugin.

Get Profile Builder

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket