Skip Navigation

[Resolved] change wpv-conditions to css class

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

Problem:

Check if a field is empty using custom coding.

Solution:

This can be done by adding the following custom shortcode to your functions.php file.

// Add Shortcode
function wp_check_field( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'id' => '',
            'field' => '',
        ),
        $atts
    );
 
    $field = get_post_meta($atts['id'],$atts['field']);
    $class = '';
   if(!empty($field[0])){
$class = '';
return;
}
    return $class;
 
}
add_shortcode( 'wp_check_field', 'wp_check_field' );

You can get the specific field information by doing this [wp_get_field id='[wpv-post-id]' field='wpcf-my-field']

This support ticket is created 6 years, 1 month 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 16 replies, has 3 voices.

Last updated by Jim 6 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1128508

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jim,

Try changing the if statement to
if(!empty($field[0])){
$class = '';
return;
}

This should resolve the issue.

Thanks,
Shane

#1128873

Jim

Yes! That's it. finally... 🙂
My issue is resolved now. Thank you!