Skip Navigation

[Resolved] Custom Search results display (no posts) until the search

This thread is resolved. Here is a description of the problem and solution.

Problem:

In this ticket the user wanted to start out with a blank results page when no search has yet been performed.

Solution:

This can be achieved by using the hook below. Add the following to your toolset custom functions in Toolset -> Settings -> Custom Code.


add_filter( 'wpv_filter_query', 'show_empty_results_default_func', 10,2 );
function show_empty_results_default_func( $query_args, $setting ) {
    if($setting['view_id'] == 9999){  
  
        if( !isset($_GET['wpv_view_count'])){
            $query_args['post__in'] = array(0);
        }
  
    }
    return $query_args;
}

Change the '9999' to the ID of your view and this should cause your view to start with an empty search page.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 16 replies, has 2 voices.

Last updated by Shane 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1336929

custom-posts Custom Search
I have 2 views: 1 for the ‘search page’ above & 1 for the ‘results page’ below.
wpv-filter-search-box placeholder="Search" output="bootstrap"
Everything works well, but I cannot figure out how to systematically start with a ‘clean’ page with no results displayed (no posts) until the search is submitted. I would like to have no entries on the ‘results page’ 1) when the user lands on the page, 2) when the page is refreshed or 3) when the search is reset using the reset button.
I have looked at the documentation and tried a filter for blank page, but couldn't make it work.
I would very much appreciate you assistance on this. Thank you.

#1336985

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

Thank you for getting in touch.

You can actually try the solution in the link below.
https://toolset.com/forums/topic/setting-empty-search-result-by-the-default-page/

Thanks,
Shane

#1337001

Hi Shane, that works fine thank you.
Do you have any experience about how to mange the 'No items found' text?
i.e. It is needed if there is a search with finds nothing, but not needed if a user hasn't submitted a text.
(I know it can be changed)
Thanks,

#1337013

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

Currently the text is showing now correct? Even when the search is not performed?

If so then you can do it like this.

[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' eq '' )"]
  no items found text can go here
[/wpv-conditional]

This will only show the no items found text if the view has not yet been searched for.

Thanks,
Shane

#1337027

Hi Shane,
Thank you for your reply.
For a user who arrives on the page, but hasn't done a search, the page is 'fresh'. When the page is 'fresh' I would like the "no items found" not to show.
When a text is performed & nothing is found I would like the "no items found" to show as usual.
Thanks for your help.

#1337861

There are 3 posibilities:
1. the user lands on the fresh search page and there is not a 'no items found' message. ??
2. the user performs a search and doesn't find anything, so there is a 'no itmes found' message. OK
3. the user performs a search and gets some results, so there is not a 'no items found' message. OK

Points 2 & 3 are fine, but is point 1. possible for a fresh page and/ or when the page is refreshed?
Thanks.

#1337889

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

This shortcode should resolve the issue for you.


[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
  no items found text can go here

[/wpv-conditional]

When a view search is triggered it adds the parameter "wpv_view_count" to the URL.

This conditional will pass for your scenarios

1. the user lands on the fresh search page and there is not a 'no items found' message. ??
A. If the user lands on the page fresh and there is no search performed then the "wpv_view_count" parameter won't be in the URL so this will fail the conditional because it only triggers when the url value is not empty.

2. the user performs a search and doesn't find anything, so there is a 'no itmes found' message. OK
A. This will cause the conditional to pass because once the search is performed then the 'wpv_view_count' parameter will get added to the url.

3. the user performs a search and gets some results, so there is not a 'no items found' message. OK
A. This section won't show because it is already preconditioned to when there is not items found.

NOTE: You must add the conditional within the [wpv-no-items-found] [/wpv-no-items-found] around the "No items found" text.

Thanks,
Shane

#1338217

Hi Shane,
Thank you for the extra details.
I have implemented this and it does one of the two things.
For point 1A 'no items found' no longer shows on the fresh page, which is perfect.
For point 2A 'no items found' no longer shows, but it should - a search is submitted and there are no results found, so the user should see the 'no items found' message.
Does this mean that you can either have the message or you cannot?
When the page is fresh there should be no message.
When a results doesn't find anything the message should show.
Any further information would help.
Thank you for your assistance.

#1338843

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

Would you mind allowing me to have access to the search so that I can have look t this for you ?

Thanks,
Shane

#1338889

Hi Shane,
Yes that's fine, but I'll have to provide you access and won't be able unitl later
Before that, here is the code you provided with where i added it. there is pobably somehting wrong. What do yout think?
THanks,

[wpv-no-items-found]
[wpv-conditional if="( '[wpv-search-term param='wpv_view_count']' ne '' )"]
[wpml-string context="wpv-views"]no items found[/wpml-string]
[/wpv-conditional]
[/wpv-no-items-found]

#1338911

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

Quick question does the parameter "wpv_view_count" appear in the URL for you after you've done a search that was unsuccessful ?

Perhaps this might be the issue as from what I see it should still work for when no results are found.

Thanks,
Shane

#1338933

HI Shane,
Here is the URL when it finds nothin. : hidden link... etc

I will open another ticket about changing the URLs, but that is a different subject I think and not for now perhaps.
Thanks.

#1338955

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

Could you change this below from.

[wpv-search-term param='wpv_view_count']

To

[wpv-search-term param='wpv_post_search']

This should resolve the issue now.

Thanks,
Shane

#1338993

Brilliant Shane. That does it.
It works exactly the way I had hoped thank you very much.

Please could you tell if the 'reset button' is only for clearing the search field OR if it is possible to clear the "not items found text" too?
Thank you.

#1339081

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi,

The reset button only resets the search fields.

If your search is an ajax based search then it should reset the search results as well given that the results and the search is on the same page.

Thanks,
Shane