Skip Navigation

[Resolved] Problem with usermeta and conditional output

This support ticket is created 7 years, 8 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 9 replies, has 3 voices.

Last updated by Beda 5 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#426044

poM

Hi,

I am trying to display conditionally usermeta fields but none of these shortcodes work :

[wpv-conditional if="( '[types usermeta="societe" output="raw"][/types]' ne '')"]<h6>[types usermeta='societe'][/types]</h6>[/wpv-conditional]
[wpv-if evaluate="'[types usermeta="societe" output="raw"][/types]' != ''"]
<h6>[types usermeta='societe'][/types]</h6>
[/wpv-if]

Please help.

#426071

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Could you clarify what condition you want to test for?

wpv-if is deprecated and you should use wpv-conditional (https://toolset.com/documentation/views-shortcodes/#wpv-conditional)

When you insert conditional shortcodes there is an option to enable debugging (you can manually add debug="true" to the shortcode instead) which when you view the page will show you the expressions you are comparing and how they are evaluated.

You can try that for yourself, but if you are still stuck then please clarify the expression you are trying to test.

#426118

poM

The answer is contained in the shortcode : this is a user meta field called "societe".

[wpv-conditional if="( '[types usermeta="societe" output="raw"][/types]' ne '')"]<h6>[types usermeta='societe'][/types]</h6>[/wpv-conditional]

#426125

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Your example is checking if the usermeta field "societe" is not equal to a closing parenthesis.

I assumed you meant to check for something else, but if that is what you intend to check for, what is the problem? You have users with a user meta field of "societe" that are equal to a closing parenthesis that are showing the contents of the conditional?

That doesn't sound very likely, so let me ask again, what is your conditional supposed to check for?

There are three parts to the answer. The term (the usermeta field "societe"), the comparison (e.g. not equal), and the value being compared (a closing parenthesis in your example, but surely something else).

#426153

poM

I just want to check if this usermeta field is empty before displaying it.

I found the shortcode on your support webiste.

#426600

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Can I suggest you use the debug mode to see what is actually being compared, by adding the parameter debug='true' to your wpv-conditional shortcode?

I set up a simple test where I added the user custom field 'societe' and filled in that field for just some of my users, leaving it blank for others.

In my case my user custom field is just a single line text field, and so if I do not fill it in, it will be empty. This may not be the case if you are using something like a select box, depending on how you have it set up, but the debug mode will reveal what is being retrieved from the database.

So I created a simple view that lists users of any role with no filters, and added the following in my loop output:

<wpv-loop>
	<p>User: [wpv-user field='display_name']</p>
	[wpv-conditional if="( '[types usermeta="societe" output="raw"][/types]' ne '')" debug='true']<p>Has societe.</p>[/wpv-conditional]
	<p>Societe is: [types usermeta='societe'][/types]</p>
</wpv-loop>

For a user that does have an entry for the societe user field, the debug output shows the following:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( 'Carrefour' ne '')
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( 'Carrefour' ne '')
--------------------
After replacing 1 general variables and comparing strings: ( 'Carrefour' ne '')
	Comparing Carrefour to 

You can see the string Carrefour is being compared to an empty string (and they are not equal).

For a user with no entry for societe, the debug info shows:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( '' ne '')
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( '' ne '')
--------------------
After replacing 1 general variables and comparing strings: ( '' ne '')
	Comparing  to 

Here we are comparing an empty string with an empty string, i.e. they are equal.

I suspect that your issue is that your empty fields are not actually empty strings, but the debug mode will reveal that.

If that still doesn't help, than please let me know.

#426635

poM

Hi,

I have finally found out that the expression was not correctly evaluated because the "societe" usermeta field contains a "''.

Should this bug be fixed ?

I have one more question regarding the ability to add parametric search functionality to a user view. I know it currently is unavailable (I don't understand why, I often work with Drupal).

Do you think it will be available in a near future ?

Cheers.

#426689

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I'm not sure it is a bug.

How have you set up your societe user meta field? What type of field is it?

How are you/your users entering the data?

Regarding parametric searches for users, it is on our roadmap—we have quite a few requests for this feature—but it requires a complete refactoring of the parametric search backend component, which is to say it is not trivial to implement. It is planned, but not currently in active development.

I have added a link to your thread to the developer feature request ticket to add your voice.

#427614

poM

OK thanks, I will open a new ticket for the filterable user view.

#1091224
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.