Sauter la navigation

[Résolu] Conditional out^put using user fields

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

The issue here is that the user wanted to get the current year dynamically.

Solution:

This can be done by using the shortcode below.

// Add Shortcode
function wpc_current_year() {
 
    return date("Y");
 
}
add_shortcode( 'wpc_current_year', 'wpc_current_year' );

Add this shortcode to the Custom Code section in Toolset -> Settings -> Custom Code and then activate it.

You should be able to get the current year with this shortcode [wpc_current_year]

Now in order to use this in the conditional you must add it to the views 3rd party shortcode arguments in Toolset -> Settings -> Frontend.

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

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

Supporter timezone: America/Jamaica (GMT-05:00)

Marqué : 

Ce sujet contient 5 réponses, a 2 voix.

Dernière mise à jour par Pat Il y a 5 années et 10 mois.

Assisté par: Shane.

Auteur
Publications
#1197651

Pat

Hello,

I have created some user custom fields :
- annee => numerical custom field
- type-membre => radio field

Now, I would like to place a condition that follows the 3 rules (AND) :
- user has author role
- annee is equal to current year
- type-membre is equal to a specific value (let say "eleveur" here)

I have a first condition for the author role :
[wpv-conditional if="( '[wpv-post-author format="meta" meta="user_level"]' eq '2' )"]

Could you help to add the other conditions?
Thanks
Pat

#1197856

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Pat,

Thank you for contacting our support forum.

I should be able to assist you with this, is it that you are going to add a fixed year value in the conditional ?

So the example would be.


[wpv-conditional if="( '[wpv-post-author format="meta" meta="user_level"]' eq '2' ) AND ( '[types usermeta="annee" id="[wpv-post-author format='meta' meta='ID']"' eq 'value' ) AND ( '[types usermeta="type-membre" id="[wpv-post-author format='meta' meta='ID']"' eq 'value' )"]


https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#syntax

Please let me know if this helps.

Thanks,
Shane

#1197879

Pat

Hi Shane,

Thanks for helping,

Concerning the year, I need to compare with the current year (ie : 2019 currently but for next year, it should be 2020 without having to change the code). If I'm right, there is a kind of parameter in Views for that ?

Regards
Pat

#1197892

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Pat,

In that case we would need to get the year dynamically.

// Add Shortcode
function wpc_current_year() {

	return date("Y");

}
add_shortcode( 'wpc_current_year', 'wpc_current_year' );

Add this shortcode to the Custom Code section in Toolset -> Settings -> Custom Code and then activate it.

You should be able to get the current year with this shortcode [wpc_current_year]

Now in order to use this in the conditional you must add it to the views 3rd party shortcode arguments in Toolset -> Settings -> Frontend.

Once you've done this you can use the shortcode in your conditional.

Thanks,
Shane

#1210186

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

resolved

#1212473

Pat

Hi Shane,

Sorry for coming back again on this topic, but something is going wrong.

I started first with the [wpv-conditional if="( '[wpv-post-author format="meta" meta="user_level"]' eq '2' )"] and it's working fine.

Then I tried to add a second condition :
[wpv-conditional if="( '[wpv-post-author format="meta" meta="user_level"]' eq '2' ) AND ( '[types usermeta="type-de-membre" id="[wpv-post-author format='meta' meta='ID']"' eq 'ELEVEUR' )"] and nothing was displayed.

If I put the shortcodes [wpv-post-author format='meta' meta='ID'] in the loop, I'm getting the post author ID and if I place [types usermeta="type-de-membre" id="[wpv-post-author format='meta' meta='ID'] also in the loop, then I'm getting the 'ELEVEUR' result

So it seems all shortcodes are working fine separately but are not working if I place them in the condition.

Another point is that I tried with this condition :[wpv-conditional if="( '[wpv-post-author format="meta" meta="user_level"]' eq '2' ) AND ( '[types usermeta="type-de-membre" id="[wpv-post-author format='meta' meta='ID']"' eq 'ELEVEUR' )"] (OR instead of AND) and nothing was displayed which is strange as the first condition should always be taken into consideration !!!

Can you find any idea on why the condition is not running well?

Regards
Pat