Skip Navigation

[Resolved] Conditional Statement for Author Meta

This support ticket is created 7 years, 3 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Noman 7 years, 3 months ago.

Assisted by: Noman.

Author
Posts
#555290

Ian

Tell us what you are trying to do?

Display author meta within a post

Is there any documentation that you are following?

I Could not find an example on the toolset site

I am using the following code to display a social icon link. The link is part of the Author profile.

<li class="et_pb_social_icon et_pb_social_network_link et_pb_social_media_follow_network_0">
					<a href="[types usermeta='ef-facebook-url' user_is_author='true' output='raw'][/types]" class="icon rounded_rectangle" title="Facebook" style="background-color: #3b5998;"><span>facebook</span></a>
	</li>

This is working as expected. What I can't seem to figure out is a conditional statement to check if the field is empty or not.

Thanks

#555332

Noman
Supporter

Languages: English (English )

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

Hi Ian,

Thank you for contacting Toolset support. You can use the conditional output on User fields, something like this:

[wpv-conditional if=" '[types usermeta='user-contact'][/types]' ne '' "]
  [types usermeta="user-contact"][/types]
[/wpv-conditional]

Check this doc for more info (Checking Types plugin shortcodes):
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

I hope it helps, Thank you

#556608

Ian

This is still not working for me. Is this checking the current user and not the author?

	[wpv-conditional if="( '[types usermeta="ef-facebook-url"][/types]' ne '' )"]
		<li class="efm_pb_social_icon et_pb_social_network_link et_pb_social_media_follow_network_0 efm-social-facebook">
			<a href="[types usermeta='ef-facebook-url' user_is_author='true' output='raw'][/types]" class="icon rounded_rectangle" title="Facebook" style="background-color: #3b5998;"><span>facebook</span></a>
		</li>
	[/wpv-conditional]
#556640

Noman
Supporter

Languages: English (English )

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

register shortcode.png

Hello Ian,

1. Please add this code in your theme’s or child theme’s functions.php file:

function check_user_meta_func($atts, $content = null) {
	
	$content = wpv_do_shortcode($content);
	if(isset($content) && $content != '')
		return 1;
	else
		return 0;
}

add_shortcode( 'check-user-meta', 'check_user_meta_func' );

2. Register the ‘check-user-meta’ shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments. See attached screenshot.

3. Then add this shortcode in your View >> Loop Output Editor:

[wpv-conditional if="( '[check-user-meta][types usermeta='ef-facebook-url'][/types][/check-user-meta]' ne '0' )"]
<li class="efm_pb_social_icon et_pb_social_network_link et_pb_social_media_follow_network_0 efm-social-facebook">
        <a href="[types usermeta='ef-facebook-url' user_is_author='true' output='raw'][/types]" class="icon rounded_rectangle" title="Facebook" style="background-color: #3b5998;"><span>facebook</span></a>
    </li>
[/wpv-conditional]

Thank you

#556672

Ian
output.jpg
conditional-statement.jpg
settings.jpg
user-field.jpg
Code-snipt.jpg

I am still not getting my expected results. Other user meta is working fine:
• Author photo displaying fine
• Author fist and last name displaying fine
• Author phone field displays fine
• Author payment fields work fine

I just can not get the Author social media links to display conditional.

I wanted to include a link: hidden link
This may be a little slow as it is a local install.

#557130

Noman
Supporter

Languages: English (English )

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

link.png

Hello Ian,

The link you have provided is not working, please see attached screenshot.

I need to take a look at your setup and to request temporary website WP-admin and FTP info for your site to debug further and to help in resolving this. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

Thank you

#557350

Noman
Supporter

Languages: English (English )

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

For some reason the conditional was not working in Divi theme or divi builder. I have created a new Content Template >> added conditional content in that >> then added that Content Template inside the page. Now its working good:
hidden link

CT link: hidden link

This is a standard alternate way, I hope its good for your now. Thank you

#557402

Ian

Norman,

Please let me apologize in advance! I was having some issues with the formatting and went in to make changes to see why my css was no longer effecting the view. I pasted stuff overtop of your work without first duplicating the view and now can not get back to what you gave me.

Sorry 🙁 it has been one of those days.

#557587

Noman
Supporter

Languages: English (English )

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

Hello,

I have again done the changes, please check now:
hidden link

Thank you