Skip Navigation

[Resolved] Not able to conditionally show or hide text/button

This support ticket is created 5 years, 10 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by anthonyD-3 5 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1187668

I am trying to:

Hide a "Create Profile" button which is a CPT, if the user/author has already created a Profile.

Link to a page where the issue can be seen:

This is a password protected page.

I expected to see:

Conditional code that I have found in an earlier thread that matches our exact scenario no longer seems to be valid or I have implemented incorrectly.

I used this reference in order to hide the button https://toolset.com/forums/topic/html-conditional-display-based-on-if-a-custom-post-exists/

Instead, I got:

Create Profile button still shows even if the user has already created a Profile

#1188260

Hi Anthony,

Thank you for contacting us and I'll be happy to assist.

The code suggested by Noman should still work.
( ref: https://toolset.com/forums/topic/html-conditional-display-based-on-if-a-custom-post-exists/#post-566831 )

Can you please share temporary admin login details for your website, so that I can log in and find the missing link?

Your next reply will be private so that you can share the access details, securely.

Important note: Please make a complete backup copy of the website, before sharing the access details.

regards,
Waqar

#1188274

This is the page that needs to have the create button hidden if the CPT of Player Profile exists for the signed in user.
hidden link

#1188275

Here is a player with a player profile created
Joe@hubforce.com
simple_password_for_you

#1188276

Here is a player that has yet to create a profile, so create button should exist.
joe@lyons.rocks
simple_password_for_you

#1188783

Hi Anthony,

Thank you for sharing the access details.

While the username and passwords for both player level users work, the one for the admin user doesn't.

Can you please check the username and password for the admin user and share it again, in the next reply.
(your next reply will be private)

regards,
Waqar

#1189606

Hi Anthony,

Thank you for waiting and for sharing the access details again.

I noticed that your website is using the WP Bakery builder plugin to construct the "Player" page.
( hidden link )

The conditional shortcode from the Toolset Views plugin ("wpv-conditional") cannot be used directly inside WP Bakery plugin's elements, but you can use the following workaround:

1. You can update your custom shortcode to:


function check_user_profile_exist_func( $atts, $content = null ) {
     
    $user = wp_get_current_user();
    $result = new WP_Query(array(
        'author'            => $user->ID,
        'post_type'         => 'player-profile', // your CPT slug
        'post_status'       => 'publish',
        'posts_per_page'    => 1,
    ));

    if (!(count($result->posts)!=0)) {
    	return $content;
    }
     
}
add_shortcode( 'check_user_profile_exist', 'check_user_profile_exist_func' );

2. After this change, you'll be able to use this shortcode directly to show some content, only to those members who haven't created a profile yet:


[check_user_profile_exist]

<div align="center">
<a class="btn skew-btn button-nlg_center nlg-create-account btn-default btn-lg  has-icon" href="/create-player-profile/">
<span class="btn-text">Create Player Profile</span><span class="btn-icon"><i class="fa fa-user"></i></span>        </a>
</div>

[/check_user_profile_exist]

I hope this helps and please let me know how it goes.

regards,
Waqar

#1189706

My issue is resolved now. Thank you!