[Gelöst] Conditional using shortcode in if not working
This support ticket is created vor 4 Jahren, 9 Monaten. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Sorry to be annoying but I have this ticket I need a faster resolution to. The below is assigned to Minesh. He's not in my timezone and we haven't started to resolve the issue. Please help.
If you're not able to, the ticket I reference in the below was answered by Shane who also happens to be in my timezone.
Currently it seems that you're not able to check the parent fields in the conditionals at the moment. I remember this being possible previously but could be a bug in this version.
I would recommend that you get this done using some custom code. What you can perhaps do is wrap our shortcode to get the field in another custom shortcode and then pass that shortcode into the conditionals.
Thanks Shane! I have started into writing a custom shortcode for this.
In the process I'm afraid I found another issue. Once I removed the wpv-conditional I found that 5 of 18 pages do not show the content of their fields (e.g. /ideas/principles/emerging-technology/)
[types field='index-description-2' item='$parent'][/types]
[types field='index-description-3' item='$parent'][/types]
even though they have contents entered in the back end. This issue may be related in that the $parent thing doesn't appear to work. It also shows this to be an intermittent issue or at least it's odd and probably complex.
Can I roll back to a version where this works as documented?
Yes you can try rolling back as i'm currently testing the problem on my end.
I'm actually trying to replicate it. Once I'm able to I will make a report to our 2nd tier supporters but I dont suspect that a solution will come quickly if i'm able to discover a bug.
Well, I wrote a shortcode that I use in the wpv-conditional to do my bidding.
This works as intended leading me to the conclusion that wpv-conditional works fine.
The issue then must be the [types field='index-description-2' item='$parent'][/types] expression, at least when it's provided as a value to the if. To test that idea further I tried providing the if a value of [wpv-post-field name="wpcf-index-description-2" item='$parent']. This was apparently also not evaluated. I think they must evaluate correctly but something messes up (a) the context in the wpv-conditional code where this code is do_shortcode-ed or (b) there is something in the rendered field that makes it fail. To check on the later suspicion I cleaned the field in text mode so there was no weird markup.
Before I did all that I tried using $current_page instead of $parent. That yields curious results:
(1) See this page versteckter Link. The first time through the loop $parent does not work. The second loop (further down the page) both $current_page and $parent work.
(2) Then check out versteckter Link here only $parent works!?
Happy to see you were able to work around the issue.
I too have come to the conclusion that in your site's case the issue occurs when you add the item parameter with an attribute like the $parent.
In other cases it works. It could just be a case where it breaks in the View Loop but works outside the loop.
There is still some testing that needs to be done here but so far I'm not able to replicate the issue.
However there is one thing I need for you to try for me on your end. If you edit a regular post and add the [types field='index-description-2' item='$parent'][/types] expression in the conditional does it still work ?
In my case on my test site it works but wanted to confirm that on your end its not a cause where it is completely broken in the conditionals.
I'm not quite sure I understand your request: However there is one thing I need for you to try for me on your end. If you edit a regular post and add the [types field='index-description-2' item='$parent'][/types] expression in the conditional does it still work ?
The regular post is the parent to the view. The post's parent would not have this field. Indeed when I add this shortcode on a post it comes back blank. versteckter Link
I also put that shortcode in the Content Template and that as expected comes back blank as well. versteckter Link
So then I thought perhaps he means a child post that is listed. So I added the shortcode to the excerpt. That post is a child and indeed the content appears. versteckter Link
Thank you for running the tests for me. I've concluded that the issue is definitely on your end as I've setup a similar scenario like your post and it works. See Screenshot
As you can see the parent information is being retrieved as intended in the conditional.
Would you mind if I went onto your site to take a copy for further debugging steps to see if I can identify anything on your site that would point me to the issue.