Skip Navigation

[Resolved] HTML conditional display based on if a custom post exists

This support ticket is created 7 years, 2 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 3 replies, has 2 voices.

Last updated by Noman 7 years, 2 months ago.

Assisted by: Noman.

Author
Posts
#566634

Hello,

I am building a website where users have the possibility to create a personal profile. This personal profile is a custom post type created via Toolset.

In their "Account" page, I want to display a link to create their personal profile if they haven't created one already. If they have created one however, I want to hide the link.

I have tried to come up with some conditional statement that would let me do this, but so far I haven't had luck.

I am relatively new to Toolset so maybe I am missing something, but any assistance on how to achieve that would be very welcome!

Many thanks!

Best,
- Julien

#566659

Noman
Supporter

Languages: English (English )

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

Hi Julien,

Thank you for contacting Toolset support. Can you please provide more info that:

1. “Personal profiles” is a custom post type and every user can create only 1 profile (post) right?
2. User can only see “create their profile link” after getting logged in right?

Thank you

#566771

Hi Norman,

Many thanks for the quick reply!

Answers to your questions:

1: yes, though I haven't actually implemented a limit, the idea is to have just 1 profile per registered user, and it is indeed a custom post type

2: yes, only logged-in users can create a profile page

Many thanks!

Best,
- Julien

#566831

Noman
Supporter

Languages: English (English )

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

Register_Custom_Shortcode & Function.png

Thank you for providing more info. You can achieve that using custom shortcode:

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

function check_user_profile_exist_func( ) {
	
	$user = wp_get_current_user();
	$result = new WP_Query(array(
		'author'			=> $user->ID,
		'post_type'			=> 'student', // your CPT slug
		'post_status'		=> 'publish',
		'posts_per_page'	=> 1,
	));
	return (count($result->posts)!=0);
	
}
add_shortcode( 'check_user_profile_exist', 'check_user_profile_exist_func' );

==> Whereas 'student' will need to be replaced with your post_type slug.

2. Register shortcode & function first ‘check_user_profile_exist’ in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments. And also in >> Functions inside conditional evaluations section -- screenshot attached.

3. Then you can use shortcode in the View like this:

[wpv-conditional if="( '[check_user_profile_exist]' eq true )"]
Link goes here
[/wpv-conditional]

I hope it helps, thank you