Skip Navigation

[Resolved] Shortcode to display content if toolset field has content

This support ticket is created 3 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Minesh 3 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2121663
Alison Blay-Palmer.png

I'm creating faculty and student pages for a graduate school. If a particular person's bio has "Publications", I'd like the title "Publications" to appear on their webpage appear along with the list of their articles (field slug = people-publications). If the bio does not have publications, then the people-publications field would be empty, but I'd like that title to not appear as well.

In this example, you can see that the Publications title is appearing (below "Awards") even though the professor has no publications listed: hidden link

Is there some kind of conditional logic in a shortcode that I can wrap around this title to make it disappear when the WYSIWYG field is empty?

Thanks!

#2122089

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I'm not sure if you are using blocks or legacy views to build your content template.

If you are using blocks then we offer conditional block.

If you are using legacy view, you can use the [wpv-conditional] shortcode to display the content conditionally. Please check the following Doc:
- https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

#2125889

Thanks, Minesh! I am using the legacy view for the template. When I put in the [wpv-conditional] shortcode, the site seems to only display the shortcode text, and doesn't check if the field "people-publications" is empty.

For example, see the shortcode visible underneath Publications here: hidden link

#2125983

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is really strange.

Can you please share temporary admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2127723

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The [wpv-conditional] shortcode is part of Views/Blocks plugin.

I've added that plugin and now if you can check the shortcode it will work.

But as you want to hide the title of the field, you will require to move the title within [wpv-conditional] shortcode rather adding as separate row.

#2129267

Brilliant. I hid the title in one of those shortcodes and it worked. Thanks, Minesh!

One related question - I'd like to be able to have the title "Research Cluster" appear underneath the photo if the person is in one (it's a checkbox with the field slug "clusters"), but disappear if not. And ideally the plural title "Research Clusters" appear if they are in more than one. Is there a way to use the shortcode to do that? Currently the "Research Cluster" title is appearing on every page.

#2129383

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is a way to check if checkckbox option for checkboxes field is checked or not.

However the workaround is to use the custom shortcode. I've added the following custom shortcode to "Custom Code" section offered by Toolset:
=> hidden link

function func_check_single_cluster() {
global $post;
  
 $value = types_render_field( "clusters", array( "separator" => ", ",'item'=>$post->ID) );
  if( strpos($value,',') !== false ) {
    return 1;
  }else{
    return 0;
  }
}
 
add_shortcode( 'check_single_cluster', 'func_check_single_cluster' );

And added the following conditionals to display "RESEARCH CLUSTER" and "RESEARCH CLUSTERS" conditionally:

[wpv-conditional if="( '[types field='clusters' output='raw' separator=', '][/types]' ne '') AND ([check_single_cluster] eq 1)"]RESEARCH CLUSTERS[/wpv-conditional][wpv-conditional if="( '[types field='clusters' output='raw' separator=', '][/types]' ne '') AND ([check_single_cluster] eq 0)"]RESEARCH CLUSTER[/wpv-conditional]
#2130159

Wow. Thanks, Minesh! That works brilliantly.

One other question I had regarded the URL fields. Occasionally these professors want to add a link to additional publications. I've created a URL field with the slug "more-publications-link" then tried to use that in a shortcode with a button that only appears if they have publications. See the bottom of hidden link. But I get stuck when trying to use that URL field in a button or an <a> tag...

#2130187

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

I kindly ask you to open a new ticket with every new question you may have.