Skip Navigation

[Résolu] [wp-if] does not work with CRED-2

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.

This topic contains 13 réponses, has 2 voix.

Last updated by jamesH-3 Il y a 6 années et 8 mois.

Assigned support staff: Waqas.

Auteur
Publications
#270018

Hi Waqas

I have closed the previous thread: https://toolset.com/forums/topic/wp-if-does-not-work-with-cred/ as I have worked out how to use [wp-if] for certain parts of a CRED form and this worked in a number of my CRED forms

I have now tried the same one on a post to limit the whole CRED forms to certain users; however, somehow it does not work:

hidden link

[wpv-if evaluate="'[wpv-current-user info="role"]'='administrator'"]
[cred_form form="Add New Coupons"]
[/wpv-if]

[wpv-if membershipstatuscondition="wpcf-membership-status" evaluate="$membershipstatuscondition='Confirmed'"]
[cred_form form="Add New Coupons"]
[/wpv-if]

[wpv-if membershipstatuscondition="wpcf-membership-status" evaluate="$membershipstatuscondition='Pending'"]
[spb_message color="alert-block" width="1/1" el_position="first last"]
You are not allowed to publish new coupons because your membership is currently pending approval.
[/spb_message]
[/wpv-if]

Thanks

PS I think I have already sent you my login credentials

#270294

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I just checked in your site at hidden link and edited this coupon post and found the code as you mentioned.

First thing, I was wondering where is "wpcf-membership-status" defined in your system? It's neither a custom field with Coupons, nor a custom field attached to this particular post. I also checked user profile, considering if it's part of user fields, but couldn't find one there too.

Secondly, as you have used the alternative syntax for the role test, you should try that for other [wpv-if] evaluations too, like:

[wpv-if evaluate="'[types field='membership-status'][/types]' = 'Confirmed'"]
	[cred_form form="Add New Coupons"]
[/wpv-if]

This should work fine, if field exists in this scope.

#270306

Hi Waqas

"wpcf-membership-status" is one of the Merchant fields (Coupon is the child of the Merchant).

I have tried the syntax you recommended; however, this did not work either:

[wpv-if evaluate="'[wpv-current-user info="role"]'='administrator'"]
[cred_form form="Add New Coupons"]
[/wpv-if]

[wpv-if evaluate="'[types field='membership-status'][/types]' = 'Confirmed'"]
[cred_form form="Add New Coupons"]
[/wpv-if]

[wpv-if evaluate="'[types field='membership-status'][/types]' = 'Pending'"]
[spb_message color="alert-block" width="1/1" el_position="first last"]
You are not allowed to publish new coupons because your membership is currently pending approval.
[/spb_message]
[/wpv-if]

Thanks?

#270580

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Alright, I have realized that what is going wrong here actually. Let me explain it.

As you mentioned that "Coupon" is the child of "Merchant":

- When you query a parent post, you can access a custom field like [types field='membership-status'][/types]
- When you query a child post, and you want to grab a custom field of parent, you do [types field='membership-status' id='$merchant'][/types] - Notice the "id" parameter, which refers to the parent post type "merchant"
- For both of above to work, your main query should belong to one of those post types (Merchant or Coupon, respectively).
- While for that hidden link post, you are trying to access the custom field of an "undefined" object, in relation to the standard post. In other words, since you are trying to evaluate or access some other CPTs, in another Post Type, this apparently makes no connection.

You should put that evaluation, in such a post which belongs to one of the target CPT.

hidden link queries in standard post type 'post', and will never reach the target, unless you provide a relation:

- Either your main query belongs to one of the CPTs
- Or you provide an explicit ID of the target post, where the fields belong to.

To demonstrate all above, I have edited that page and have put a string under each evaluation block (i.e. Works 1, Works 2, Works 3 ...). You can see the first one works fine, since that doesn't belong to any CPT, but with user role.

You can see the 2nd one doesn't work, even it has $merchant defined as ID (to parent CPT), since the main loop doesn't belong to that.

You can see the 3rd one working, because I provided an explicit ID to a post in Merchants post type.

Other blocks don't work also, for the same reason as 2nd one doesn't work.

You should create a View for this purpose, so you query for one of the CPTs. And can get your related evaluations to work.

#270588

Thanks Waqas for tge explanation. Can you please explain the solution a little more? How do you suggest I should incorparate a view with my current cred form?

#270764

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I see that you create a user for "Merchant" also. I will suggest you to move membership-status with User Accounts, so you can easily make it work on the page. Since, user account is retrievable throughout the WP Session, a user field can be queried easily.

#270888

Hi Waqas

This does not work either:

[wpv-if evaluate="'[wpv-current-user info="role"]'='administrator'"]
Works 1
[cred_form form="Add New Coupons"]
[/wpv-if]

[wpv-if evaluate="'[wpv-current-user info="membershipstatuscustom"]'='Pending'"]
[spb_message color="alert-block" width="1/1" el_position="first last"]
You are not allowed to publish new coupons because your membership is currently pending approval.
[/spb_message]
[/wpv-if]

[wpv-if evaluate="'[wpv-current-user info="membershipstatuscustom"]'='Confirmed'"]
[cred_form form="Add New Coupons"]
[/wpv-if]

Thanks
Zaf

#270890

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Please use [types user_meta="my-field"][/types] to grab the custom field attached with the user, as below:

[types user_meta="membershipstatuscustom" user_current="true"][/types]

This will return the value of "membershipstatuscustom" custom field attached with the account of currently logged in use.

Please remember, [wpv-current-user] returns information about standard user fields only.

Please see for more information:

- https://toolset.com/documentation/functions/#textfield
- https://toolset.com/documentation/views-shortcodes/#wpv-current-user

#271101

This is not working either:

[wpv-if evaluate="'[wpv-current-user info="role"]'='administrator'"]
Works 1
[cred_form form="Add New Coupons"]
[/wpv-if]

[wpv-if evaluate="'[types user_meta="membershipstatuscustom" user_current="true"][/types]'='Pending'"]
[spb_message color="alert-block" width="1/1" el_position="first last"]
You are not allowed to publish new coupons because your membership is currently pending approval.
[/spb_message]
[/wpv-if]

[wpv-if evaluate="'[types user_meta="membershipstatuscustom" user_current="true"][/types]'='Confirmed'"]
[cred_form form="Add New Coupons"]
[/wpv-if]

If you are not really sure that the solutions you are coming up with may or may not work, I am happy for you to trial it on my site?

Thanks

#271258

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I have observed the issue in your site after login again. The issue isn't related to CRED or [wpv-if], but is related with [types user_meta="..."][/types] short code.

I have reported the issue to the relevant Dev Team, they will look into this and will come up with a solution. Please do not change access details. I also created a "Test Author" user in your site, please do not remove that also (feel free to change password for now), Dev Team may need it and may change it's password if needed.

I will update you as soon as I hear back. Your cooperation and patience is much appreciated, thanks.

#272242

Any updates?

#272254

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I have just followed up again with the Dev Team. I will update you as soon as I hear back.

Thank you for your cooperation and patience.

#282508

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I got a reply from the Dev Team and the issue has been resolved. Please consider followings:

- wpv-if conditionals using the wpv-current-user shortcode were working fine
- wpv-if conditionals using the types shortcode were not working fine because the syntax was wrong.

Please notice the syntax of the short code is:

[types usermeta="membershipstatuscustom" user_current="true"][/types]

Please notice "usermeta" is the correct name of the attribute. It's been written incorrectly in the documentation and will be updated soon. I apologize for this confusion.

Your page has been updated by our Dev Team with all these corrections and it works fine now.

Please check and confirm, thank you.

#284303

Thanks