Skip Navigation

[Resolved] Show no results until filtered

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.

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)

This topic contains 14 replies, has 2 voices.

Last updated by andyB-12 4 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1733601

hidden link

hidden link

EDIT:
And the customer would like, that the first results show when clicking on the button and that no results show before clicking the button the first time.

#1734109

Nigel
Supporter

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

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

Screenshot 2020-08-11 at 08.39.37.png

Hi Andy

You are using Blocks to create your Views, right?

You can do this by wrapping the Loop output section of the View in a Conditional block, where the condition checks for the presense of a URL parameter which is always added when filtering a View, but which isn't present on the first page load.

I assume you already have set up a View block which contains search filters and has the output set up, and all you need to know is how to not initially show any results.

In the screenshot you can see what we are aiming for.

It's slightly tricky with the block navigator but you can hopefully manage.

With the View block selected, add a Conditional block at the end of the View within the View Output block, but outside of the Loop block.

Set up the condition. You'll need to switch to the Advanced editor, and then you can paste in the following condition:

  ( ( '[wpv-search-term param='wpv_view_count']' ne '' ) )

Use the little up/down paddles on the left side of the block to position it so that it is withing the Output block and before the View Loop block.

Now use the grab handle (in between the up/down paddles) and drag the View Loop block and drop it on the Conditional block drop target.

At this point, you should be able to verify with the Block Navigator at the top that you have the same structure as per my screenshot, with the View Output block containing the Conditional block which contains the View Loop block.

Update the page, and then when you visit the front-end you should be able to confirm that initially no results are shown, and they appear once you perform a search or apply a filter.

#1737547

Hey there I am using Divi and the legacy builder for views and I integrate them via shortcode into my Divi Archive. I am only creating the results with the block editor.

Does this change how I can achieve to not show results on initial load of the page?

#1737651

Nigel
Supporter

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

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

OK, in that case, instead of using a Conditional Block, you need to insert a conditional shortcode in the Loop Editor of your View output, to wrap the wpv-items-found section.

Your Loop Editor section should look something like this:

[wpv-layout-start]
[wpv-items-found]
[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="loop-item-in-filter-things"]
	</wpv-loop>
	<!-- wpv-loop-end -->
[/wpv-conditional]
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]
#1745375

Thank you. I used it for this search form, but somehow now it only shows 2 results instead of 3 results like before.

hidden link

#1745543

Nigel
Supporter

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

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

From what I can see on the front-end, there are only two results to display.

You are adding this View to an archive (which you are using Divi to design). This in itself isn't really intended. Because this is an archive, a query is made by WordPress to retrieve the relevant posts. But you are discarding this query, and using Views to make a new query which largely duplicates the effort of the initial query and so is somewhat wasteful, given that you can use Toolset to customise the archive rather than replacing it.

Anyway, working with what you have, can you first try inserting this same View onto a normal page. How many results does it display then? If it still displays two and you are sure there should be three, what happens if you remove those conditional shortcodes used to hide the output until a filter is selected?

#1745585

I just deleted the conditional shortcodes and you can see all 3 results now:
hidden link

#1745595

Nigel
Supporter

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

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

Can I get credentials to check your site? I want to look closer with the debugging turned on.

I will mark your next reply as private so that I can get log-in credentials from you—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 of your site.

#1746181

Nigel
Supporter

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

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

I first tested the View on a normal page, where it worked correctly.

I suspected the issue was with the setting to "Don't include current page in query result" when used on an archive (that setting is likely to understand the first post of the archive as the "current page"), and having unchecked that and re-visited the archive, I can see that all three results now show, if you'd like to confirm that for yourself.

#1753513

Hey Nigel,

thanks for you help. Now all results are shown correctly, but somehow the styling of the view more button on my other views is not working properly anymore.

hidden link

hidden link

The styling I created within the block editor looks different and worked before adding the conditional shortcode.

#1753551

Nigel
Supporter

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

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

I can see the issue on your site, where the button looks different if I remove the conditional shortcodes.

I need to do some testing on my own local site to reproduce the problem, and I'll get back to you in a little while when I've done that.

#1753607

Nigel
Supporter

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

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

I can't reproduce it on a basic site with the same set-up as you, so I think it must occur when Divi is added to the mix.

I'll return to testing this with Divi included and update you again.

#1753609

Hey Nigel,

no worries, you can close this ticket. I just added some lines of CSS to Divi and those overwrite the style from the block and now the buttons look good.

Thanks for your help with the conditional shortcode!

#1753621

Nigel
Supporter

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

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

OK, great, please go ahead and mark as resolved.

Thanks for letting me know.

#1753631

My issue is resolved now. Thank you!