Skip Navigation

[Resolved] Conditional output does not work when used an Content Template

This thread is resolved. Here is a description of the problem and solution.

Problem: Complex conditionals are breaking down and not displaying correctly.

Solution: There are some known limitations with long, complex conditionals. Sometimes it is necessary to break these up into multiple templates.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional

0% of people find this useful.

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Amr 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1287819

Amr
Screen Shot 2019-07-09 at 7.57.24 AM.png

I am using conditional in a Custom Post Type content template to evaluate the value of a custom field and output accordingly. See the following:

[wpv-conditional if="( $(wpcf-status) eq 'Published' )"]
... Some Fields like [wpv-post-title] and [wpv-post-body view_template="None"]
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-status) eq 'Draft' )"]
... Some Text
[/wpv-conditional]

When viewing the CTP, the conditional logic works in that it is able to distinguish between custom posts whose "wpcf-status" is "Published" or "Draft" and output the correct info. However, the output that contains any fields like [wpv-post-title] or [wpv-post-body] does not get interpreted to display the values of these fields put instead, it literally output the field shortcode like [wpv-post-title] and [wpv-post-body].

If I get rid of the conditional all together, the output works properly and all display fields show their values. Please see attached screenshot output that shows the literal display of fields name instead of field values when used inside a conditional in a Content template.

Conditionals work properly in a View, but do not seem to work in a Content template for a CPT.

Please help.

Thanks.

#1287857

Hi, that's unusual. Can you try these troubleshooting steps?
- Temporarily switch to a default theme like Twenty Nineteen, then deactivate all plugins except Types and Views. Test again.
- If the problem is resolved, reactivate your theme and other plugins one by one until the problem returns.
- If the problem is not resolved, I'll need to take a closer look.

#1288103

Amr
Screen Shot 2019-07-09 at 11.58.05 AM.png
Screen Shot 2019-07-09 at 11.53.22 AM.png
Screen Shot 2019-07-09 at 11.49.02 AM.png
Screen Shot 2019-07-09 at 11.49.19 AM.png

Hi Christian,

I deactivated all plug-in except Types and Views and I switched theme to Twenty fouthteen. See screenshot.

I still have the problem. I am using the latest version of Toolset.

I have also attached the content template code that I am using.

#1288143

Okay thanks. Can you try a more simplified Content Template? Save your current template and create a new one with this code:

[wpv-conditional if="( $(wpcf-status) eq 'Published' )"]
[wpv-post-title]: [types field="status"][/types]
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-status) eq 'Draft' )"]
[wpv-post-title]: [types field="status"][/types]
[/wpv-conditional]

Are nested shortcodes displayed correctly now? If not, can you confirm the eval function is enabled on your server? You may need your host's assistance here. https://toolset.com/toolset-requirements/

#1288157

Amr

Hi Christian,

Yes replacing the content template with the code you sent works. Why is my code not working?

Amr

#1288173

I'm not quite sure yet. It could be a typo somewhere in the Content Template that is causing problems, or there could be another problem I'm not aware of yet. I would try adding a small amount of content and test, then repeat until the problem returns. You may be able to find one small piece of code that causes the problem. If so, then we can take a closer look. All I have to go on now is a screenshot of code, so it's hard for me to tell.

#1288229

Amr

Hi Christian,

I did some testing and I can tell you that there is definitely an issue with Content Templates that use conditionals with complex content. I was able to make it work by removing some of the content. In the second row <div class="row" style="font-size:90%;"> if I remove the second and third column (<div class="col-sm-4">) , it works. It does not matter which column content I remove, as long as there is only one column, then it works. Here is the code:

[wpv-conditional if="( $(wpcf-status) eq 'Published' )"]

<div class="row">
<div class="col-sm-4">
[wpv-conditional if="( '[wpv-post-featured-image output="url"]' eq '' )"]
<img src="/wp-content/uploads/2019/07/APATT.jpg">
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-featured-image output="url"]' ne '' )"]
[wpv-post-featured-image size="medium"]
[/wpv-conditional]
</div>

<div class="col-sm-8" style="line-height:1.2em;">
<div style="font-size:115%;font-weight:bold;padding-top:10px;">[wpv-post-title]</div>
<span style="font-size:80%;">By: [wpv-post-author]</span><br>
<span style="font-size:80%;">Status: [types field='status'][/types] - Topic(s): [wpv-post-taxonomy type="topic"]</span><br>

[wpv-conditional if="( $(wpcf-status) eq 'Draft' )"]
<span style="font-size:80%;">( [cred_link_form form="Edit APATT" text="Edit"] - [cred_link_form form="Publish APATT" text="PUBLISH"] - [cred_delete_post_link action="delete" text="Delete" redirect='138' message="Are you sure you want to delete this APATT?" message_show="1" class="cred-refresh-after-delete"] )
</span>
[/wpv-conditional]

[wpv-conditional if="( ('[wpv-current-user info="role"]' eq 'superuser') OR ('[wpv-current-user info="role"]' eq 'administrator') ) AND ( $(wpcf-status) eq 'Published')"]
<span style="font-size:80%;">( [cred_link_form form="Unpublish APATT" text="Unpublish"] )</span>
[/wpv-conditional]

[types field='context'][/types]
</div>
</div>

<hr>

<div class="row" style="font-size:90%;">

<div class="col-sm-4">
<div class="level"><b>[types field='level-1'][/types]</b><br></div>
<div class="authenticmaterial">[types field='authentic-material-description-1' output='raw'][/types]<br></div>

<div class="communicationmode">Interpretive</div>
<div class="interpretivetask">[types field='interpretive-task-description-1' output='raw'][/types]<br></div>
[types field='interpretive-task-i-can-1' output='raw'][/types]<br>
<hr>
<div class="communicationmode">Interpersonal</div>
<div class="interpersonaltask">[types field='interpersonal-task-description-1' output='raw'][/types]<br></div>
[types field='interpersonal-task-i-can-1' output='raw'][/types]<br>
<hr>
<div class="communicationmode">Presentational</div>
<div class="presentationaltask">[types field='presentational-task-description-1' output='raw'][/types]<br></div>
[types field='presentational-task-i-can-1' output='raw'][/types]
<hr>
</div>

<div class="col-sm-4">
<div class="level"><b>[types field='level-2'][/types]</b><br></div>
<div class="authenticmaterial">[types field='authentic-material-description-2' output='raw'][/types]<br></div>

<div class="communicationmode">Interpretive</div>
<div class="interpretivetask">[types field='interpretive-task-description-2' output='raw'][/types]<br></div>
[types field='interpretive-task-i-can-2' output='raw'][/types]
<hr>
<div class="communicationmode">Interpersonal</div>
<div class="interpersonaltask">[types field='interpersonal-task-description-2' output='raw'][/types]<br></div>
[types field='interpersonal-task-i-can-2' output='raw'][/types]
<hr>
<div class="communicationmode">Presentational</div>
<div class="presentationaltask">[types field='presentational-task-description-2' output='raw'][/types]<br></div>
[types field='presentational-task-i-can-2' output='raw'][/types]
<hr>
</div>

<div class="col-sm-4">
<div class="level"><b>[types field='level-3'][/types]</b><br></div>
<div class="authenticmaterial">[types field='authentic-material-description-3' output='raw'][/types]<br></div>

<div class="communicationmode">Interpretive</div>
<div class="interpretivetask">[types field='interpretive-task-description-3' output='raw'][/types]<br></div>
[types field='interpretive-task-i-can-3' output='raw'][/types]
<hr>
<div class="communicationmode">Interpersonal</div>
<div class="interpersonaltask">[types field='interpersonal-task-description-3' output='raw'][/types]<br></div>
[types field='interpersonal-task-i-can-3' output='raw'][/types]
<hr>
<div class="communicationmode">Presentational</div>
<div class="presentationaltask">[types field='presentational-task-description-3' output='raw'][/types]<br></div>
[types field='presentational-task-i-can-3' output='raw'][/types]
<hr>
</div>

</div>

[/wpv-conditional]

[wpv-conditional if="( $(wpcf-status) eq 'Draft' )"]
[wpv-conditional if="( '[wpv-post-author]' eq '[wpv-current-user info="login"]' ) OR ( '[wpv-current-user info="role"]' eq 'superuser') OR ( '[wpv-current-user info="role"]' eq 'administrator')" debug="false"]
This post type status is: [wpcf-status] and you are the owner of this post or you are a superuser or administrator.
[/wpv-conditional]
[/wpv-conditional]

#1288707

Okay there is a known issue with complex conditional content, as mentioned in the documentation here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional

You can try breaking up the content into multiple templates, or you can try adding this line to your wp-config.php file:

ini_set('pcre.jit', false);

This turns off a specific regex algorithm that causes problems with conditional evaluation in some versions of PHP.

#1288889

Amr

Hi Christian,

Adding ini_set('pcre.jit', false); to the wp-config.php did not help.

However, breaking up the content into multiple conditionals did help and I was finally able to display the full content. I had to repeat the exact same conditional 4 times to get it to work.

My issue is resolved now. Thank you!