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;
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?
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";
}
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"
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";
}
Thanks Minesh. It worked.