Skip Navigation

[Résolu] Struggling with wpv-conditional shortcode on child post edit content template

This support ticket is created Il y a 6 années et 2 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Marqué : 

Ce sujet contient 13 réponses, a 3 voix.

Dernière mise à jour par Minesh Il y a 6 années et 1 mois.

Assisté par: Minesh.

Auteur
Publications
#1115145

I have parent post student-profile, child post course and custom field gender belonging to student-profile. The custom field is a radio type with 3 values Male, Female and Not Disclosed in both the display text and custom field content fields. I have a View selecting courses containing a toolset post edit shortcode linking to a Content Template which displays field values from courses and the edit version of a form which updates courses. I'm testing with a single student profile with a value for the gender field of female. In the Content Template, I'm trying to display content if the student is female but struggling!

If I add [types field='gender' item='@student-profile-course.parent'][/types] to the CT, the output is Female so there isn't an issue with the value of this field. I've tried these numerous ways of writing the wpv-conditional shortcode but they all return nothing:-

[wpv-conditional if="( $(wpcf-gender).id(student-profile) eq 'Female' )"]I'm Female[/wpv-conditional]
[wpv-conditional if="( $(wpcf-gender).id(post) eq 'Female' )"]I'm Female[/wpv-conditional]
[wpv-conditional if="( $(wpcf-gender item='@student-profile-course.parent') eq 'Female' )"]I'm Female[/wpv-conditional]

Conversely, if I use ne instead like this, the output is I'm not Male. Whilst this is correct output it's not the argument I want to use and I don't understand why the eq argument isn't working.

[wpv-conditional if="( $(wpcf-gender).id(student-profile) ne 'Male' )"]I'm not a Male[/wpv-conditional]
[wpv-conditional if="( $(wpcf-gender).id(post) ne 'Male' )"]I'm not a Male[/wpv-conditional]
[wpv-conditional if="( $(wpcf-gender item='@student-profile-course.parent') ne 'Male' )"]I'm not a Male[/wpv-conditional]

Can you clarify things for me please?

#1115590
radio.JPG

Hello,

If you are using the shortcode

[wpv-conditional if="( $(wpcf-gender).id(student-profile) eq 'Female' )"]I'm Female[/wpv-conditional]

It will use the "wpcf-gender" field value( Custom field content) in database, it might be something different from [types] shortcode outputting, Types shortcode will output "Display text" by default.

You should check the settings of custom field "gender", see screenshot radio.JPG

#1115757
custom field value from post.JPG
gender custom field values.JPG

As I said initially the values for display text and custom field content are the same. Please see uploaded images (one showing custom field radio values, the other showing database content for the parent post).

#1116134

Thanks for the information, the shortcode:

[wpv-conditional if="( $(wpcf-gender).id(student-profile) eq 'Female' )"]I'm Female[/wpv-conditional]

works only for the old post type relationship, which is setup a custom field "_wpcf_belongs_student-profile_id" in the child course post, in you case, I suggest you use the Types shortcode insider [wpv-conditional], for example:

[wpv-conditional if="( '[types field='gender' item='@student-profile-course.parent'][/types]' )" debug="true"]
I'm Female
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#1116920

I've tried that one already (I advised this in my first post about this issue)

#1116938

It works fine in my localhost:

[wpv-conditional if="( '[types field='gender' item='@student-profile-course.parent'][/types]' )" debug="true"]
I'm Female
[/wpv-conditional]

See above answer:
https://toolset.com/forums/topic/struggling-with-wpv-conditional-shortcode-on-child-post-edit-content-template/#post-1116134

Please check these in your website:
1) In case it is a compatibility problem, please deactivate other plugins, and switch to wordpress default theme 2017, and test again

2) If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1117088
conditional shortcode creation.JPG

I can see now that I hadn't tried using the types field shortcode after all. Using this works. I don't see how your example shortcode will work; it doesn't contain a whole argument:-

[wpv-conditional if="( '[types field='gender' item='@student-profile-course.parent'][/types]' )" debug="true"]I'm Female
[/wpv-conditional]

and shouldn't the quotes inside the shortcode be like this ", not like this ' ???

This is really frustrating because my instinct is to use the conditional button when I'm editing the Content Template to create the code (see image) but when I do it this way the code created looks like this:-

[wpv-conditional if="( $(wpcf-gender).id(post) eq 'Female' )"]I'm Female[/wpv-conditional]

and even if I select from Parent post instead, the resulting condition doesn't use types shortcodes

If this format won't work why is it even possible to create this style of shortcode??

What's even more confusing is if I use a conditional shortcode to directly compare the value of a field in the current post with a field in the parent post, I don't have to use the types shortcode. A format like this (on the same Content Template) works:-

[wpv-conditional if="( $(wpcf-start-date) lt $(wpcf-enrol-date item='@student-profile-course.parent') )"] This course started before you enrolled[/wpv-conditional]

so why doesn't the conditional with 'eq' or 'ne' arguments work in this format??

Furthermore in the documentation here https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/ the example code for using types shortcode is missing parentheses so that wouldn't have worked even if I'd found it.

[wpv-conditional if=" '[types field="consultant-price-per-hour"][/types]' gt '0' "]Price per hour: [types field="consultant-price-per-hour"][/types] [/wpv-conditional]

There are also NO examples at all about using shortcodes in conditions for related posts on this help page and no links to such documentation either.

It's taken a whole week of trial & error testing and trying to find the right information. Something has to change!

#1117099

Yes, you are right, it will be changed:
Here is the feedback from our developers:
We probably want to go with the syntax that is used everywhere, $(wpcf-slug).item(@relationship.role)
including in the [wpv-conditional] shortcode.

But there isn't any ETA for it, so currently, I suggest you use the shortcode directly.

#1119789

After further development of my site and trying to get the format of this right so it works as required, I'm finding that in some places the format needs to be like this:-

[wpv-conditional if="( '[types field="gender" item="@student-profile-course.parent"][/types]'  )"]
I'm Female
[/wpv-conditional]

and in others it will only work using this format:-

[wpv-conditional if="( [types field='gender' item='@student-profile-course.parent'][/types]  )"]
I'm Female
[/wpv-conditional]

This is really frustrating and I'm wasting a lot of valuable time on this. We've not had to use the types custom field shortcode inside wpv-conditional shortcodes before and with it not working consistently, our website content is likely to be incorrect. Addressing this needs to be given some priority and I'd appreciate being informed when it's been sorted as I'll need to change all my conditional shortcodes.

#1119929

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Luo is on vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.

Well - could you please share problem URL where the said conditional shortcode works and does not work. I need both problem URL so I can check why it's working in the first place and not working in another place.

I have set the next reply to private which means only you and I have access to it.

#1120408

The site is in development and completely locked down. I'm happy to demonstrate this by sending you zipped copies of my database and files (these would be two separate files not a Duplicator file so the right fields need to be enabled to allow upload).

Before I prepare these, please confirm the correct format as this isn't at all clear to me at the moment.

Thanks

#1120665

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Well - we always recommend the duplicator copy of site as it help us to install the exact copy of site without editing database for URLs etc...

If you do not have the duplicator, please make sure you deactivate/remove all security plugins you install otherwise I will not be able to install the database and setup your site on my local test server.

Please share exact problem URLs where the conditional shortcode works and does not works.

I have set the next reply to private which means only you and I have access to it.

#1122259

Hi Minesh

On closer inspection I've found it's not the location that changes the required format of the conditional shortcode, it's the type of conditional.

For example, if the conditional output is based on the value of a custom field, the conditional shortcode will only work in this format:-

[wpv-conditional if="( '[types field="gender" item="@student-profile-course.parent"][/types]' eq 'Female' )"] I'm Female[/wpv-conditional]

If the conditional output is based on comparing the values of two custom fields, the conditional shortcode will only work in this format:-

[wpv-conditional if="( [types field='licence-due-date' item='@student-profile-course.parent' output='raw'][/types] lt [types field='start-date' output='raw'][/types] )"][wpv-post-title]'s licence is due for renewal before this course starts[/wpv-conditional]

This is painstaking work. Luo indicated the developers are looking to adopt the $(wpcf-slug) syntax everywhere but there's no ETA for it! This needs to be given some priority and I'd appreciate a heads up when the relevant upgrade has been released please.

#1122670

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

well - I checked the ticket and I see there is still no ETA on it but its been already escalated to our Devs. As a supporter, we can report the issue but can not fix it as its totally depends upon our Devs predefined priorities and available resources.

However, I added your voice to our internal ticket. The only solution is to go with the format that works for now. Additionally, the format you are going to use will not be broken, so do not worry about it.

Thank you for understanding.