Hi the code is below
[wpv-conditional if="( '[types usermeta='your-roles'][/types]' eq '' )"]
pls update
[/wpv-conditional]
[wpv-conditional if="( '[types usermeta='your-roles'][/types]' ne '' )"]
<span class="ep_roles">
[types usermeta='your-roles' separator="</span><span class='ep_roles'>" current_user="true"][/types]</span>
[/wpv-conditional]
the first part suppose to output "pls update " but its not .
second part output fine .
pls advice if you see any mistake in the code. thanks.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Is it just that you are missing the parameter current_user="true" in your first example?
It seems to work okay on a test site of mine.
Hi, The field is user form checkboxes field.
the first part is sstill not working well.
[wpv-conditional if="( '[types usermeta='your-roles current_user='true'][/types]' eq '' )"]
pls update
[/wpv-conditional]
The field is user form checkboxes field with 4 checkbox options.
from here : https://toolset.com/forums/topic/conditional-display-with-multi-checkboxes-field-type/#post-746505
Minesh said : Checkboxes fields are not supported for conditional post field display.
is this still the same case?
[types usermeta='how-did-you-hear-about-us' current_user='true' state="checked" option="0"]Banners[/types]
[types usermeta='how-did-you-hear-about-us' current_user='true' state="checked" option="1"] Media [/types][types usermeta='how-did-you-hear-about-us' current_user='true' state="checked" option="2"]Human [/types]
[types usermeta='how-did-you-hear-about-us' current_user='true' state="checked" option="3"] ads[/types]
[types usermeta='how-did-you-hear-about-us' current_user='true' state="checked" option="4"]Youtube [/types]
Hi,. the above code works , BUT how do i put conditional if nothing[none selected ] is selected output " no result" ? How to merget them all. ?
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
I did some testing and found that it doesn't appear to work, even though in our documentation it says it should: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-types-checkboxes-field-for-non-empty-value
I'm reporting that so that it can be investigated. It should either work, or the documentation should be changed.
In the meantime as a workaround I crafted a simple custom function you can use in your conditional shortcodes.
<?php
/**
* Function to test if user checkboxes field set
*/
function user_condition( $field ){
$userid = get_current_user_id();
$return = "";
if ( isset( $field ) ) {
$value = get_user_meta( $userid, $field, true );
if ( empty( $value ) ) {
$return = "empty";
}
}
return $return;
}
You will need to register the function user_condition at Toolset > Settings > Front-end content to be able to use it in the conditional shortcode.
You pass the field slug (with the 'wpcf-' prefix if it is a Types field), like so:
[wpv-conditional if="( user_condition( 'wpcf-prediction' ) eq 'empty' )"]
User condition says empty!
[/wpv-conditional]
So, if no checkboxes are checked the function will return the string 'empty'. You can either test with 'eq' or 'ne' as it suits.
hi, this shortcodes has some issue , is the code closed well for a shortcode snippets ?
pls raise this issue of the checkboxes issue to the 2nd tier while we try to find a solution. thanks.
ok, after some testing i understand that this fn is only to detect if any checkboxes fields is checked. thanks.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
I heard back from my colleague who pointed out that where I had reported it not working I had a simple typo in the shortcode. I double checked and they were right.
So, testing once more, I found that the following worked:
[wpv-conditional if="( '[types usermeta='prediction' current_user='true' output='raw'][/types]' ne '' )"]
<p>Prediction: [types usermeta='prediction' current_user='true'][/types]</p>
[/wpv-conditional]
There I am testing whether any one of the options of a checkboxes user field is checked. I tested inserting it directly in a page, and inside a Form.