I am trying to:
Conditionally display the recommendation textbox section if the recommendation text is not empty.
Link to a page where the issue can be seen:
hidden link
I expected to see:
For the coronavirus masks post, there is no recommendation text, so the recommendation text box should not be visible.
Instead, I got:
You can see the recommendation text box for that post.
<div class="selfhelplistingarea">
<div class="row">
<div class="col-sm-4">
<a href ="[types field='product-url' output='raw' target='blank' rel='noopener noreferrer' class="selfhelp-header1"][/types]"target='blank' rel='noopener noreferrer' >[wpv-post-featured-image size="medium"]</a>
</div>
<div class="col-sm-8">
<div class="selfhelp-header1">
<a href ="[types field='product-url' output='raw' target='blank' rel='noopener noreferrer' class="selfhelp-header1"][/types]"target='blank' rel='noopener noreferrer' >[types field='product-title'][/types]</a>
</div>
<div class ="selfhelp-details">[types field='author-provider'][/types] <p class="mobile-para"></p>[types field='product-price' class ="contact"][/types]<p class="mobile-para"></p><a href ="[types field='product-url' output='raw' target='blank' rel='noopener noreferrer'][/types]"target='blank' rel='noopener noreferrer' class="selfhelp-header1"> Buy from [types field='retailer' class="selfhelp-header-link"][/types] <i class="fas fa-external-link-alt"></i></a>
</div>
<div id="module" class="container">
<p class="collapse" id="collapse-[wpv-post-id]" aria-expanded="false"><b>Description: </b>[types field='product-description' output='raw'][/types]</p>
<a role="button" class="collapsed" data-toggle="collapse" href="#collapse-[wpv-post-id]" aria-expanded="false" aria-controls="collapse"></a>
</div>
[wpv-conditional if="( NOT(empty($(wpcf-recommendation-text))) )"]
<div class="recommendationarea">
<div id="module" class="container">
<p class="collapse" id="collapse-[wpv-post-id]-[wpv-post-id]" aria-expanded="false"><i class="fas fa-user-circle"></i> <b>Recommended by [types field='suggested-by' class ="reco"][/types]: </b>"[types field='recommendation-text' output='raw'][/types]"</p>
<a role="button" class="collapsed" data-toggle="collapse" href="#collapse-[wpv-post-id]-[wpv-post-id]" aria-expanded="false" aria-controls="collapse"></a>
</div>
</div>
[/wpv-conditional]
</div>
</div>
</div>
Hello, can you turn on debug for this conditional temporarily, and test again?
...
[wpv-conditional if="( NOT(empty($(wpcf-recommendation-text))) )" debug="true"]
...
Let me know what is displayed in the debug information for the Corona masks post. Also, what type of field is recommendation-text?
Hi Christian,
Thanks for your help - that is the debug on and the same issue occurs.
Recommendation-text is a single line custom field.
Thanks for your help - that is the debug on and the same issue occurs.
Okay when you turn on debug, there should be some technical information output on the front-end of the site. I need to see that information, but I can't find it on the front-end now. Did you turn off debug? Can you turn it on temporarily and copy the output for this post, then include that in your next reply?
If debug is currently "on" but there is no output generated, please try this alternative syntax:
[wpv-conditional if="('[types field="recommendation-text" output="raw"][/types]' ne '' )" debug="true"]
Hi Christian, I still had the original debug on when you checked - the debug information was not shown.
I replaced this with your new syntax, but still the debug information is not shown (this syntax is still in place).
<div class="selfhelplistingarea">
<div class="row">
<div class="col-sm-4">
<a href ="[types field='product-url' output='raw' target='blank' rel='noopener noreferrer' class="selfhelp-header1"][/types]"target='blank' rel='noopener noreferrer' >[wpv-post-featured-image size="medium"]</a>
</div>
<div class="col-sm-8">
<div class="selfhelp-header1">
<a href ="[types field='product-url' output='raw' target='blank' rel='noopener noreferrer' class="selfhelp-header1"][/types]"target='blank' rel='noopener noreferrer' >[types field='product-title'][/types]</a>
</div>
<div class ="selfhelp-details">[types field='author-provider'][/types] <p class="mobile-para"></p>[types field='product-price' class ="contact"][/types]<p class="mobile-para"></p><a href ="[types field='product-url' output='raw' target='blank' rel='noopener noreferrer'][/types]"target='blank' rel='noopener noreferrer' class="selfhelp-header1"> Buy from [types field='retailer' class="selfhelp-header-link"][/types] <i class="fas fa-external-link-alt"></i></a>
</div>
<div id="module" class="container">
<p class="collapse" id="collapse-[wpv-post-id]" aria-expanded="false"><b>Description: </b>[types field='product-description' output='raw'][/types]</p>
<a role="button" class="collapsed" data-toggle="collapse" href="#collapse-[wpv-post-id]" aria-expanded="false" aria-controls="collapse"></a>
</div>
[wpv-conditional if="('[types field="recommendation-text" output="raw"][/types]' ne '' )" debug="true"]
<div class="recommendationarea">
<div id="module" class="container">
<p class="collapse" id="collapse-[wpv-post-id]-[wpv-post-id]" aria-expanded="false"><i class="fas fa-user-circle"></i> <b>Recommended by [types field='suggested-by' class ="reco"][/types]: </b>"[types field='recommendation-text' output='raw'][/types]"</p>
<a role="button" class="collapsed" data-toggle="collapse" href="#collapse-[wpv-post-id]-[wpv-post-id]" aria-expanded="false" aria-controls="collapse"></a>
</div>
</div>
[/wpv-conditional]
</div>
</div>
</div>
Something else must be going on, the debug information should be displayed here. May I log in and take a closer look?
I think there has been a disconnect somewhere, because the conditional is not placed in the template that is currently displayed in the View's loop. Please follow along:
First, I edit the page we are discussing:
hidden link
Then I click to edit in Elementor, and I am redirected here:
hidden link
The page contains a View "Product listings 2 view". I can go to Toolset > Views to find the View, and edit the View here:
hidden link
If you look in the Loop Editor, you can see a Content Template is placed in the loop. That Content Template has a slug "selfcare-products-2". Just below the Loop Editor, I can see a different template is linked to the View. That is NOT the template placed in the loop, just to be clear. This usually happens when you manually change the contents in the Loop Editor to use a different template than the one that was originally designed in the View's Loop Wizard. So do not click "Edit with Block Editor", that will not change the results in the View. Instead, go to Toolset > Content Templates and edit the Selfcare products 2 template, and you can edit the selfcare-products-2 template here:
hidden link
I can't see the conditional anywhere in this code. My guess you're editing a similar template somewhere instead of the correct template. Please add the conditional in this template and check the results again, or update the View's loop editor to point to the correct template you want to use.
My issue is resolved now. Thank you!