Tell us what you are trying to do?
I'm building a CPT archive using Toolset Blocks. All works fine except the conditional block, which I am checking against a parent field.
I constructed the first conditional block using the visual editor; the raw code is.
( ( $(theme-anchor).item(@themeparent-axischild.parent) = 'place' ) )
The full conditional, with "Yes" in para block just to test, is:
[wpv-conditional if=" ( ( $(theme-anchor).item(@themeparent-axischild.parent) eq 'place' ) ) " ]<!-- wp:paragraph -->
<p>yes</p>
<!-- /wp:paragraph -->[/wpv-conditional]
The "Yes" [or blank] is not present as expected. [When I get it working, I'll conditionally insert an image, not the "Yes."]
I know that the parent/child relationship is working, as I inserted below the conditional block a single text block (again using visual editor), and the correct output is achieved. The raw code for this block is:
<div class="tb-field" data-toolset-blocks-field="1" data-last-update="1.4">[types field='theme-anchor' item='@themeparent-axischild.parent'][/types]</div>
What is the link to your site?
See hidden link for archive page. You'll see the theme-anchor field displaying either "place," "knowledge," or "action" as the three values for this field. You won't however see the "Yes" for the test para block in the four cases (15 total records) where it should evaluate to true.
I thought this may have something to do with the dashes I used to construct CPT slugs, and eliminated them but no change. There are of course dash characters in fieldname slugs. Are dashes still an issue anywhere in Toolset?
Thank you,
Jim P.
Hello,
It is hard to debug this issue with only one frontend URL, I suggest you try these:
Add debug="true" attribute into the wpv-conditional shortcode, for example:
[wpv-conditional if=" ( ( $(theme-anchor).item(@themeparent-axischild.parent) eq 'place' ) ) " debug="true"]<!-- wp:paragraph -->
<p>yes</p>
<!-- /wp:paragraph -->[/wpv-conditional]
It will help you to debug [wpv-conditional] shortcode, more help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional
If you need more assistance for it, please provide you website credentials in below private message box, thanks
Thanks for the details, since the custom field "theme-anchor" is created with Types plugin, it needs to add "wpcf-" slug prefix, I have changed the condition as below:
( ( $(wpcf-theme-anchor).item(@themeparent-axischild.parent) eq 'place' ) )
Please test again, check if it is fixed.
More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/
when you are accessing custom fields through native WordPress functions, you need to prepend the wpcf- prefix to the slug
Yes, I believe this has fixed the issue; thank you.
Can you please clarify, however, why the Conditional block does not prepend the wpcf- when constructing the conditional via visual editor, if indeed executing this condition entails a native WP function vs. the Toolset API? This would seem to be an issue you could readily address, and is not at all intuitive for users like me.
I will address the shortcode issue I posted at bottom of previous reply in a separate thread.
Regards,
Jim P.
Since you are using the Toolset Conditional block, you can follow our document to setup the condition as below with shortcode:
( ( '[wpv-post-field name="wpcf-theme-anchor" item="@themeparent-axischild.parent"]' eq 'place' ) )
More help:
https://toolset.com/course-lesson/using-toolset-conditional-block/#checking-for-shortcodes-values
The codes I mentioned above works for the WP shortcode block with wpv-conditonal shortcode:
https://toolset.com/forums/topic/conditional-block-w-parent-field-not-evaluating-correctly/#post-2125937
See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional
My issue is resolved now. Thank you!