Skip Navigation

[Resolved] wpv-conditional with wpcf-view

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 7 replies, has 2 voices.

Last updated by katjaL 1 year, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2536953

Hi,

I need to show conditionally in a bootstrap tab a text if this certain view (composer-news) has results. With single fields I would make the condition like this:

[wpv-conditional if=" NOT ( empty( $(wpcf-somefield)) ) " ]this is my link to the content[/wpv-conditional]

and I tried this, doesn't work:

[wpv-conditional if=" NOT ( empty( $(wpcf-view name ="composer-news")) ) " ]this is my link to the content[/wpv-conditional]

#2537665

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

First of all - are you sure your view is not returning any result even space. Are you using block view or classic view? Can you please share edit page screenshot of your view?

#2538455

Thank you Minesh,
This is a content template with bootstrap tabs. And we want to show the tab only if the tab has content. This certain tab contains a view (list of news, called composers-news).

The content template is done with blocks and the bootstrap tabs is a html block. Here is the code in html block:
[wpv-conditional if=" NOT ( empty( $(wpcf-view name ="composers-news")) ) " ]<li class="nav-item">Publications & news[/wpv-conditional]

At the moment the tab never shows even though there is content (I forgot to mention this!). If I delete the condition, the tab shows - but of course it shows even there is no content which is not what we want.

#2538473

Minesh
Supporter

Languages: English (English )

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

What if you try to use the following code:

[wpv-conditional if="( '[view name ='composers-news']' ne '' )"] 
 <li class="nav-item"><a class="nav-link" id="news-tab" data-toggle="tab" href="#news" role="tab" aria-controls="news" aria-selected="false">Publications & news</a>
[/wpv-conditional]

More info:
- https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/

#2538499

Unfortunately no change.

#2538505

Minesh
Supporter

Languages: English (English )

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

Then I will require problem URL and admin access details to check whats going wrong with your setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.

#2538579

Minesh
Supporter

Languages: English (English )

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

The reason why it was not working is views return the blank spaces even when no result are there. To fix that we have to add custom shortcode to trim the view's result. Can you please check now.

Composer who has some news: hidden link
and who hasn't any: hidden link

I've added the following shortcode to "Custom Code" section offered by Toolset:
=> hidden link

add_shortcode( 'render-view', function($atts){
   
  $content = trim(render_view( array( 'name' => $atts['name']) ));
  
  
  return $content;
});

I've changed the conditional statement as given under:

[wpv-conditional if="( '[render-view name='composers-news']' ne '')"]<li class="nav-item"><a class="nav-link" id="news-tab" data-toggle="tab" href="#news" role="tab" aria-controls="news" aria-selected="false">Publications & news</a></li>[/wpv-conditional]

And I've registered the above "render-view" shortcode at: Toolset => Settings => Front-end Content => Third-party shortcode arguments

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

#2538595

WOW Minesh, perfect!! My issue is resolved now. Thank you!