Skip Navigation

[Résolu] Using custom shortcodes in conditionals over user fields doesn't work

This support ticket is created Il y a 7 années et 1 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

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

Dernière mise à jour par linaS Il y a 7 années.

Assisté par: Beda.

Auteur
Publications
#586170

I'm trying to conditionally show some user fields at user page.

This is front:

      [wpv-conditional if="( '[types usermeta='twitter' user_id='[queried_object_id]' output='raw'][/types]' ne '' )"]   
<li><a href="[types usermeta='twitter' user_id='[queried_object_id]' output='raw'][/types]" class="twit2"  target="_blank" title="Twitter"><i class="fa fa-twitter"></i></a></li>
      [/wpv-conditional]

There is shortcode:

function queried_object_id( $attr ) {
	return get_queried_object_id();
}
add_shortcode( 'queried_object_id', 'queried_object_id');

Functions registered:
lien caché

But this conditional is always false and nothing is shown...

How to fix it?

#586219

Toolset User Fields are not appearing in the GUI for conditional output.
I reported this so we can work on this problem.

To check upon user Fields you can do this:

[wpv-conditional if="( '[types usermeta='your-field-slug' user_is_author='true' output='raw'][/types]' eq 'here' )"]
 Output if value is "here"
[/wpv-conditional]

But that works only where you have a Post Object and an author - or if you pass an User ID, or the current logged in user.

It seems you want to do that on the Author Archives and there you have no author of a post as usual.
get_queried_object_id() returns just the right value.

You can try this with the simple shortcode:

function my_object(){
	$object = get_queried_object_id();

	var_dump($object);
}

add_shortcode('my_object', 'my_object');

Hence you can use that ShortCode in a condition like this:

[wpv-conditional if="( '[types usermeta='your-field-slug' user_id=='[my_object]' output='raw'][/types]' eq 'here' )"]
 Output if value is "here"
[/wpv-conditional]

This works fine locally. Can you try again with this syntax?
It works in my tests.

#586255

Emm, what's the difference from what I did already?

#586992

That code is what I tested locally.

Have you tried what I pasted?
Eventually you are not on a pure Author Page?

If this does not work on your side, can you confirm the issue also persists with no other Plugin and Theme Twenty Seventeen?

If so, I think I'll need a copy of your site.
https://toolset.com/faq/provide-supporters-copy-site/

Could you provide me that?
(This is in order to run some debug tools locally)

#588005

I did it like this:

function user_has_field( $field )
{
	if( get_user_meta( get_queried_object_id(), $field, true ) )
		return true;
	else
		return false;
}

      [wpv-conditional if="( user_has_field('wpcf-twitter') )"]   
<li><a href="[types usermeta='twitter' user_id='[queried_object_id]' output='raw'][/types]" class="twit2"  target="_blank" title="Twitter"><i class="fa fa-twitter"></i></a></li>
      [/wpv-conditional]