Home › Toolset Professional Support › [Resolved] Conditional view
Problem:
How to display conditional output within views
Solution:
You can use [wpv-conditional] shortcode to display the conditional output.
You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/conditional-view-5/page/2/#post-623726
Relevant Documentation:
https://toolset.com/documentation/views-shortcodes/#wpv-current-user
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)
Tagged: Views, Views plugin
This topic contains 24 replies, has 2 voices.
Last updated by bouchairY 6 years, 10 months ago.
Assisted by: Minesh.
Hello
I have a view wich list some items of a cpt offers, i added via ACF Pro, a True/False metafield ( visible_sur_le_front ) to each offer
I want to display offer only if visible_sur_le_front =1
My template for this view is :
[wpv-conditional if="( $(visible_sur_le_front) eq '1' )"] <article style="display: inline-block; opacity: 1;"> <div class="image_holder"> <a class="portfolio_link_for_touch" href="[wpv-post-url]"> <span class="image">[wpv-post-featured-image size='custom' width='550' height='550' crop='true' attr="class=attachment-portfolio_list size-portfolio_list wp-post-image"]</span> <span class='circuit'></span> </a> <span class="text_holder"> <span class="text_outer"> <span class="text_inner"> <span class="feature_holder"> <span class="feature_holder_icons"> <a class="preview" href="[wpv-post-url]" target="_self"> </a> </span> </span> </span> </span> </span> </div> <div class="portfolio_description"> <h4 class="portfolio_title">[wpv-post-link] xx[wpv-post-field name='visible_sur_le_front']xx</h4> </div> </article> [/wpv-if]
Thank you for your help
Hello. Thank you for contacting the Toolset support.
Well - it looks like the code you are using is wrong as you are using [wpv-conditional] shortcode and ending the shortcode with [/wpv-if]
Here is the correct syntax:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#syntax
For example
[wpv-conditional if="(expression)"] What will be done if the expression is true [/wpv-conditional]
It seems you need to use [wpv-post-field] shortcode in order to access the field "visible_sur_le_front" value.
In your case, could you please try to use following code:
[wpv-conditional if="( '[wpv-post-field name='visible_sur_le_front']' eq '1' )"] <article style="display: inline-block; opacity: 1;"> <div class="image_holder"> <a class="portfolio_link_for_touch" href="[wpv-post-url]"> <span class="image">[wpv-post-featured-image size='custom' width='550' height='550' crop='true' attr="class=attachment-portfolio_list size-portfolio_list wp-post-image"]</span> <span class='circuit'></span> </a> <span class="text_holder"> <span class="text_outer"> <span class="text_inner"> <span class="feature_holder"> <span class="feature_holder_icons"> <a class="preview" href="[wpv-post-url]" target="_self"> </a> </span> </span> </span> </span> </span> </div> <div class="portfolio_description"> <h4 class="portfolio_title">[wpv-post-link] xx[wpv-post-field name='visible_sur_le_front']xx</h4> </div> </article> [/wpv-conditional]
More info:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field
Hello. Thank you for contacting the Toolset support.
Well - it looks like the code you are using is wrong as you are using [wpv-conditional] shortcode and ending the shortcode with [/wpv-if]
Here is the correct syntax:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#syntax
For example
[wpv-conditional if="(expression)"] What will be done if the expression is true [/wpv-conditional]
It seems you need to use [wpv-post-field] shortcode in order to access the field "visible_sur_le_front" value.
In your case, could you please try to use following code:
[wpv-conditional if="( '[wpv-post-field name='visible_sur_le_front']' eq '1' )"] <article style="display: inline-block; opacity: 1;"> <div class="image_holder"> <a class="portfolio_link_for_touch" href="[wpv-post-url]"> <span class="image">[wpv-post-featured-image size='custom' width='550' height='550' crop='true' attr="class=attachment-portfolio_list size-portfolio_list wp-post-image"]</span> <span class='circuit'></span> </a> <span class="text_holder"> <span class="text_outer"> <span class="text_inner"> <span class="feature_holder"> <span class="feature_holder_icons"> <a class="preview" href="[wpv-post-url]" target="_self"> </a> </span> </span> </span> </span> </span> </div> <div class="portfolio_description"> <h4 class="portfolio_title">[wpv-post-link] xx[wpv-post-field name='visible_sur_le_front']xx</h4> </div> </article> [/wpv-conditional]
More info:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field
Hello
Thank you for your reply
Ok it is hidden now but I have a 3 columns layout and know I have a blank item intsead of remove it
Please find below the loop output
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <div class="container wpv-loop js-wpv-loop projects_holder clearfix v3 standard"> <wpv-loop wrap="3" pad="true"> [wpv-item index=1] <div class="row no-gutter"> <div class="col-sm-4">[wpv-post-body view_template="element-de-boucle-dans-circuits_tags"]</div> [wpv-item index=2] <div class="col-sm-4">[wpv-post-body view_template="element-de-boucle-dans-circuits_tags"]</div> [wpv-item index=3] <div class="col-sm-4">[wpv-post-body view_template="element-de-boucle-dans-circuits_tags"]</div> </div> [wpv-item index=pad] <div class="col-sm-4"></div> [wpv-item index=pad-last] <div class="col-sm-4"></div> </wpv-loop> </div> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] <strong>[wpml-string context="wpv-views"]Aucun item trouvé[/wpml-string]</strong> [/wpv-no-items-found] [wpv-layout-end]
Thank you for your help
so what you want to do with blank item? you want to remove it?
Hello
If visible_sur_le_front']' eq '1'
ITEM is diplayed normally (for every user, connected or not)
If visible_sur_le_front']' eq '0'
ITEM is displayed ONLY for users with role as administrator, editor, manager, agent via the shortcode below :
[user_role_editor roles="administrator, editor, manager, agent"] ITEM [/user_role_editor]
Thank you in advance
Sorry - I didnt get what you are saying. Could you please tell me what is your expected results with test case example.
Hello
Sorry that you haven't understand what I need
[wpv-conditional if="( '[wpv-post-field name='visible_sur_le_front']' eq '1' )"] <article style="display: inline-block; opacity: 1;"> <div class="image_holder"> <a class="portfolio_link_for_touch" href="[wpv-post-url]"> <span class="image">[wpv-post-featured-image size='custom' width='550' height='550' crop='true' attr="class=attachment-portfolio_list size-portfolio_list wp-post-image"]</span> <span class='circuit'></span> </a> <span class="text_holder"> <span class="text_outer"> <span class="text_inner"> <span class="feature_holder"> <span class="feature_holder_icons"> <a class="preview" href="[wpv-post-url]" target="_self"> </a> </span> </span> </span> </span> </span> </div> <div class="portfolio_description"> <h4 class="portfolio_title">[wpv-post-link]</h4> </div> </article> [/wpv-conditional] [wpv-conditional if="( '[wpv-post-field name='visible_sur_le_front']' eq '0' )"] [user_role_editor roles="administrator, editor, manager, agent"] <article style="display: inline-block; opacity: 1;"> <div class="image_holder"> <a class="portfolio_link_for_touch" href="[wpv-post-url]"> <span class="image">[wpv-post-featured-image size='custom' width='550' height='550' crop='true' attr="class=attachment-portfolio_list size-portfolio_list wp-post-image"]</span> <span class='circuit'></span> </a> <span class="text_holder"> <span class="text_outer"> <span class="text_inner"> <span class="feature_holder"> <span class="feature_holder_icons"> <a class="preview" href="[wpv-post-url]" target="_self"> </a> </span> </span> </span> </span> </span> </div> <div class="portfolio_description"> <h4 class="portfolio_title">[wpv-post-link] xx[wpv-post-field name='visible_sur_le_front']xx</h4> </div> </article> [/user_role_editor] [/wpv-conditional]
Thank you
What if you change the order of condition.
[user_role_editor roles="administrator, editor, manager, agent"] [wpv-conditional if="( '[wpv-post-field name='visible_sur_le_front']' eq '0' )"] <article style="display: inline-block; opacity: 1;"> <div class="image_holder"> <a class="portfolio_link_for_touch" href="[wpv-post-url]"> <span class="image">[wpv-post-featured-image size='custom' width='550' height='550' crop='true' attr="class=attachment-portfolio_list size-portfolio_list wp-post-image"]</span> <span class='circuit'></span> </a> <span class="text_holder"> <span class="text_outer"> <span class="text_inner"> <span class="feature_holder"> <span class="feature_holder_icons"> <a class="preview" href="[wpv-post-url]" target="_self"> </a> </span> </span> </span> </span> </span> </div> <div class="portfolio_description"> <h4 class="portfolio_title">[wpv-post-link] xx[wpv-post-field name='visible_sur_le_front']xx</h4> </div> </article> [/wpv-conditional] [/user_role_editor]
OR
Even better - you can check the user role with [wpv-conditional] shortcode as well.
For example:
[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'editor' ) OR ( '[wpv-current-user info='role']' eq 'manager' ) OR ( '[wpv-current-user info='role']' eq 'agent' ) "] Display your content [/wpv-conditional]
Hello
Thank you for your reply
The code is not working !
1. When we are not connected, no items are displayed (notconnected.png)
2. When a user is connected, items are displayed but not correctly (connected.png)
Thank tou
Well - could you please share problem URL and your expected output with information which posts should display and which posts should be eliminated.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I think you missed the following information to share: What is your expected output with information which posts should display and which posts should be eliminated.
Please see attched image
First, select all offers of type : Circuits
At the last columns, you can see : the metafield : visible_sur_le_front wich is checked or not checked
IF "visible_sur_le_front" is checked (green), offer is displayed for all users "connected" or "not connected"
IF "visible_sur_le_front" is not checked (red), offer is displayed only fou users "connected"
Thank you
Could you please check now:
=> hidden link
I've made changes to your view's loop output section and added the conditional shortcode there instead of content template. You should check the view's loop output:
=> hidden link
I see its working fine - could you please confirm.
Hello
When the user is not connected, no item are displayed !!
Normally all checked items (green) must be displayed
Thank you