Skip Navigation

[Resolved] Conditional statement for Checkboxes

This support ticket is created 5 years, 10 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by LandruF8417 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1207286

I need to display images based on ticked checkboxes. My code look like this but its not displaying anything:

if( get_post_meta($postid, 'wpcf-fields-checkboxes-option-3b523391ec2e1ba70f61380a8def398-1', true) ):
echo '<img src="hidden link">';
endif;

#1207415

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - as I understand you are using PHP template where you want to display conditional content based on the checkboxes selected - correct?

#1207618

Yes that's correct

#1207717

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - you can use the following code to check checkboxes conditionally:

global $post;
$option_0_checked = types_render_field("replace-field-slug",array('item'=>$post->ID,'option'=>0,"state"=>"checked"));
$option_1_checked = types_render_field("replace-field-slug",array('item'=>$post->ID,'option'=>1,"state"=>"checked"));
$option_2_checked = types_render_field("replace-field-slug",array('item'=>$post->ID,'option'=>2,"state"=>"checked"));
......


If($option_0_checked==replace_checkbox_option_0_value){
echo "option 0 checked";
}
If($option_1_checked==replace_checkbox_option_1_value){
echo "option 1 checked";
}
#1207849

I tried this and it did not work:

global $post;
$option_0_checked = types_render_field("wpcf-fields-checkboxes-option-3b523391ec2e1ba70f61380a8def398-1",array('item'=>$post->ID,'option'=>0,"state"=>"checked"));
$option_1_checked = types_render_field("wpcf-fields-checkboxes-option-251eeca1f66c64f351bd1e38d84bbb71-1",array('item'=>$post->ID,'option'=>1,"state"=>"checked"));

If($option_0_checked == 1){
echo "AV checked";
}
If($option_1_checked == 1){
echo "DIS checked";
}

Am I using the right slug and value?

Should the slug be "wpcf-slug-set-in-types" or the generated id of the specific checkbox in the CPT edit form?

The default values for both are "1"

#1207852

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please use the following code where you need to use "slug-set-in-types" but WITHOUT prefix "wpcf-":

global $post;
$option_0_checked = types_render_field("slug-set-in-types",array('item'=>$post->ID,'option'=>0,"state"=>"checked"));
$option_1_checked = types_render_field("slug-set-in-types",array('item'=>$post->ID,'option'=>1,"state"=>"checked"));

If($option_0_checked == 1){
echo "AV checked";
}
If($option_1_checked == 1){
echo "DIS checked";
}
#1207866

Thanks Minesh. It worked.