Skip Navigation

[Escalated to 2nd Tier] Conditional display: if user checkbox not ticked

This support ticket is created 4 years, 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by David 4 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#1614347

Hi there,

I want to display something in my template only if a custom user field checkbox is not ticked. In this case the user is the post author.

There are two places I would like this to work :
single posts template
author archive

I have tried the following code:

single posts:

[wpv-conditional if="'[types usermeta='not-advertising' user_id='[wpv-post-author format='meta' meta='ID']' ][/types]' ne '1'"]
DO SOMETHING
[/wpv-conditional]

author archive:

[wpv-conditional if="'[types usermeta='not-advertising' user_id='[archive_author]' output='raw' ][/types]' ne '1'"]
DO SOMETHING
[/wpv-conditional]

Neither of these are working for me.

Oh and I couldnt figure out how to place the debug="true" .

#1615063

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

It's not so easy to add conditions using types user fields like this.

I first inserted a types user field directly into the editor to generate the shortcode in the right format, and then added that to a conditional shortcode.

This is what I ended up with, and if I have understood what you are aiming for I think it is what you need:

[wpv-conditional if="( '[types usermeta='visible' user_is_author='true'][/types]' ne '1' )"]
Surprise!
[/wpv-conditional]
#1615079

Hey thanks Nigel. That works for my single content template.

But not on my author archive. I think the problem there might be that I'm using it outside the loop.

This is why I was using user_id='[archive_author]' , based on a custom shortcode:

function archive_author_func( $atts ) {
if(get_query_var('author_name')) {
$curauth = get_user_by('slug', get_query_var('author_name'));
} else {
$curauth = get_userdata(get_query_var('author'));
}
return $curauth->ID;
}
add_shortcode( 'archive_author', 'archive_author_func' );

That seems to be working for displaying other fields, but not in the conditional.

Is there any option for this?

#1615177

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You registered your custom shortcode at Toolset > Settings > Front-end Content under "Third-party shortcode arguments"?

#1616725

yes. And it is returning the correct ID.

I'm also finding that my single posts version is not working. I thought this was, but now I look again it is not:

[wpv-conditional if="( '[types usermeta='not-advertising' user_is_author='true'][/types]' ne '1' )"]

Can you take a look?

#1616741

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, let me get credentials and I can check the set up.

I will mark your next reply as private, you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup.

When you say single posts, you are referring to the built-in Post post type?

#1617033

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Let's see.

The author Barbara has the Not advertising field checked and so it is equal to 1.

If I output your author_archive shortcode it correctly outputs her ID.

If I output the types field, passing the user_id manually, then it correctly outputs 1.

If I output the types field passing the user_id via your shortcode it also correctly outputs 1.

So far so good.

Now to the conditional shortcode.

Trying the condition while passing the user_id manually seems to work. The condition is if the types field is not equal to 1. Well it's not, and nothing is output, so that's okay.

Now to the crunch test, the same, but with the user_id passed by your shortcode.

Also works!

Nothing is output.

So, let me verify by editing Barbara's profile, and unchecking the checkbox, so that the value will no longer be 1.

Ah. That doesn't work correctly.

Fiddling around a little I notice the debug info isn't working properly, as if the custom shortcode is breaking the conditional shortcode to such an extent that even that doesn't work.

I'm conscious that this is a live site and I don't want to break anything, so I'm going to take a copy of the site so that I can test it more thoroughly locally.

I've set up something very similar on my local site and it works correctly, so it is something specific to your site I need to pin down.

I'll get back to you.

#1617037

If you haven't copied it already - it's big - I have a dev site you can use

#1619485

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Yes, it's large, but I managed to take a copy, which I've installed locally and where I get the same results.

Something breaks the conditional shortcode such that it doesn't even show the debug info.

I need to pass this up to the second tier so that some deeper debugging can be performed, so I'm marking this as escalated and will get back to you when I have some more news.

#1623101

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

So we were able to reproduce this in the end on a clean site, and are seeking clarity from the Views developer as to whether it is expected to work, and requesting a fix if so.

When I have a reply from them, I'll let you know the details.

#1624163

Hi Nigel.

Thanks for your perseverance with this. It's much appreciated.

You guys rock!