Hi,
I went through a bunch of threads and tried different implementations but nothing was working. Can you take a look at this and let me know if the syntax is correct?
[wpv-conditional if="( CONTAINS(#(topic),'daf-yomi') ) AND ( $(wpcf-contact-role).item(@person-to-shiur-location.parent) eq 'Maggid Shiur' ) "]
Specifically the AND wpcf-contact-role, do I need to use the views shortcode version: [wpv types field="contact-role" etc..] like that? Do I use id@ instead of item@?
I simply want to make sure that a certain checkbox is checked (i.e. contains that name in the statement above), for the information inside this conditional to display.
Thanks!
Hello,
How do you setup the custom fields "daf-yomi" and "contact-role"?
You can provide a test site with the same problem, also point out the problem page URL, I need a live website to test and debug, thanks
I am not sure where do you setup those shortcodes, but in your case, you can display the "contact-role" checkboxes field second option value with shortcode:
[types field="contact-role" item="@person-to-shiur-location.parent" option="1"][/types]
And use above shortcode in [wpv-conditional] shortcode, like this:
[wpv-conditional] if="( '[types field="contact-role" item="@person-to-shiur-location.parent" option="1"][/types]' eq 'Maggid Shiur')"]
Here display something
[/wpv-conditional]
More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
option:
"zero-based index number"
e.g. option=”0″ Will output the value for the option number specified.
When I tried that piece of code just now, it hid all nested view items, not just the ones that weren't eq 'Maggid Shiur'.
If you navigate to "Views" then select -> "Nested Shiurim" then scroll down to the section -> "Loop item in Nested Shiurim", you will see a lot of custom code. The very first line of code will have this conditional: [wpv-conditional if="( CONTAINS(#(topic),'daf-yomi') )"]
- I am trying to get that to be combined with the above code you sent me with the contact-role, as in one long AND conditional, but it isn't working...
Since this piece of code is encapsulating the entire Loop item, the wpv closing tag is all the way at the bottom of the Loop.
Thanks!
I assume we are talking about these
1) post view "Nested Shiurim" in your website:
hidden link
It is querying "Shiurim" posts
2) The custom field "Contact Role" is in another custom post type "People"
3) And you are using below post type relationships:
- many-to-many relationship between "People" and "Shiurim"
hidden link
Can you confirm above website settings? above many-to-many relationship slug is "person-to-shiur", it is not "person-to-shiur-location".
And shortcode attribute item="@person-to-shiur-location.parent" won't work for many-to-many relationships, since there might be multiple "person" posts are connected with current "Shiurim" post, it won't be able to know which "person" you want to check.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
1 - Correct
2 - Correct
3 - I believe I set up the relationship as a one-to-one, is it possible to have changed to many-to-many automatically, if certain posts connected to other posts multiple times?
Is there any other way to make this conditional statement work? Even if there are many people, the reason I want to compare it to the multi-checkbox is because each person has only 1 unique "role" per shiur, so that multi-checkbox in the person CPT creates a uniqueness for each post. So can the end of the statement which says "... eq 'I am unique' " make it work?
Thanks!
As I mentioned above, you are using many-to-many relationship between "People" and "Shiurim"
hidden link
It is possible with nested view, and I have checked the problem page:
hidden link
You have already used a nested view in it, so if you setup three level nested views, it will conduct performance problem, in my opinion, you can consider these:
1) Setup another one-to-one relationship between "People" and "Shiurim", for example "maggid-shiur-person-to-shiurim"
2) Edit each Shiurim post, connect it with "People", who has "Maggid Shiur" option enabled
3) Then use below shortcode in wpv-conditional shortcode to check the result
[types field="contact-role" item="@maggid-shiur-person-to-shiurim.parent" option="1"][/types]
If I went ahead and created this new one to one relationship, that won't create performance issues?
For step 2, is there a technique in Toolset that I would be able to tell the system to automatically assign a relationship if "Maggid Shiur" is checked?
Also, I would prefer not to have that third level nested view, but with the current Nested Shiurim view, I could not figure out how to display in the view a field from another (a third) CPT - the "person" CPT. Do you know if there is another way to display related fields without having to create and add a whole new nested view? I would delete the entire third level if so.
Thanks,
Sim
Q1) one-to-one relationship won't create performance issues
Q2) there isn't such kind of built-in feature, you might consider custom codes, for example, use WordPress action hook save_post to setup the related "People" post to specific post who has "Maggid Shiur" option enabled
https://developer.wordpress.org/reference/hooks/save_post/
Q3) I am not sure why do you need such kind of complicated post type relationships structure, and in your case, you can consider to setup one-to-many relationship between "People" and "Shiurim", so the shortcode attribute item="@person-to-shiur-location.parent" should be able to work too.
Okay thank you.
Regarding Q3, the reason I needed to create this third level view, is because I am not just pulling the [wpv-post-title], I am doing it conditionally by checking the checkbox with this statement: [types field="contact-role" option="0" state="checked"]Rabbi: [wpv-post-title] [/types]
I already have a relationship between person - shiur , but I am unable to figure out how to use the attribute item="@person-to-shiur-location.parent" . I need to make sure that the statement won't display any random person-[wpv-post-title] connected to the shiur, rather it must specifically display the post title of the person that is connected with the contact-role option "0" checked. Would you know of the syntax to make this work? Because simply adding item="@person-to-shiur-location.parent" to the types field shortcode above isn't working for me..
The only way I was able to get this to work was to create a whole new view, and add the above types field contact-role shortcode to the view, and then add the view into the content template of the parent view (shiur-location).
Thanks!
Please check my answer above:
https://toolset.com/forums/topic/conditional-display-for-related-checkbox/#post-2291517
1) You are using many-to-many relationship between post types "People" and "Shiurim"
hidden link
So shortcode attribute "item" won't work
2) In order to achieve the result, you will need add another level child post view
- Query "People" posts
- Filter by:
a) post type relationship between post types "People" and "Shiurim"
b) custom field "contact-role" value
- In view's loop, display what you want.
Since you have already used a nested views, it will conduct performance problem, please let me know if you need assistance to setup such kind of child post view.
I believe that exactly what you are saying to do is what I have already set up.
I was asking if there was a way to get rid of this third nested view ( the wpv-view called nested-rabbis) and instead be able to directly relate the correct person to the main view, the shiur-location loop post via the contact role field. It seems you are saying there is no way to do this because the only way would be with the attribute item, and that does not work because it is a many to many relationship. So I will have to resort to a slow system / performance problem because there's no alternate solution.
Did I get this all clearly and we're on the same page?
I was wondering, I think I asked above but I don't believe I got an answer: I remember setting up the person-to-shiur relationship as a 1 to 1. Is it possible to have changed by itself? For example, if I accidentally added another person as a relation to a specific shiur that was already connected to a person beforehand, will Toolset allow it to occur, and dynamically change the whole relationship to a 1 to Many? or will Toolset not allow it altogether. (and in my case I simply created a different relationship than I originally thought.)
Thanks,
Simcha
Yes, in order to get rid of nested views, you can try one-to-one relationship, and you can not switch from many-to-many to one-to-one directly, you need to create new one-to-one relationship manually.
My issue is resolved now. Thank you!