I have a conditional in a shortcode block in my view:
[wpv-conditional if="( '[count_instances field= 'wpcf-field_resource_link_title' ]' > '1' )" debug="true"]<p style="margin: 0; padding: 0"><b>Resources:</b></p>[/wpv-conditional]
Its not working (no debug output even with debug switch true).
I expected my shortcode to give a value > 1 (I tested it on a post for which it has the value 2) and the conditional if to be true.
But instead nothing happened.
Do I have a syntax error? I checked here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
It seems count_instances is not a ShortCode of Toolset.
Given this is a 3rd party (custom code or other software) you would have to register it for usage in conditionals under Toolset > Settings > Front end content > Third-party shortcode arguments.
If that doesn't already solve the issue, it depends on what your ShortCode is returning, because classically an HTML conditional will work if you compare "proper" data to related data, you can check this by comparing if "1 eq 1" in the Conditional for example.
If that works in your case, then the issue is due to the values given back by the ShortCode (Custom Method) or whatever value used in the comparison operators.
1. May I ask if you used this ShortCode Method here?
https://toolset.com/forums/topic/count-number-of-entries-in-repeating-field/#post-1207355
==> There should be easier methods as well to do that:
https://toolset.com/forums/topic/how-to-count-repeated-field/#post-412049
2. In either case, the main questions are:
- what does count_instances output on its own if inserted to the Loop?
- does it produce any HTML around its value?
- is the value correct?
If it produces any HTML the condition will break, if it produces a slightly different value, it won't work either.
If all this is not the case - the only remaining issue could be the apostrophes not interchanging (" should alternate with ', hence [wpv-conditional if="( '[count_instances field= "wpcf-field_resource_link_title"]' > '1' )" debug="true"]<p style="margin: 0; padding: 0"><b>Resources:</b></p>[/wpv-conditional])
Please let me know if any of the above helped to solve this issue.
The problem was not registering it as a 3rd party shortcode. My issue is resolved now. Thank you!