Skip Navigation

[Resolved] If a user choose a category or anything in the search form, it not shows correct

This support ticket is created 4 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
- 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 21 replies, has 2 voices.

Last updated by fred-r.M 4 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1351699

Dear Nigel

Okay, yes, I agree about those 5 seconds and ongoing showing.

Second, yes, I need a solution, where we have in a first stage no result showing. And once the user is either choose something from the drop downs or use the text search, it will showing results according.

If You can help me with this wpv_filter_query API filter, would be great, I am not 100% familiar how to do that.

Regards

#1351721

Nigel
Supporter

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

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

You can add this code to your site (at Toolset > Settings > Custom Codes), you should just need to edit the ID of the View:

/**
 * No initial results
 *
 * Don't show View results until a filter has been applied
 * 
 * Tests for custom field filters, taxonomy filters, or text searches
 */
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
  
	$target_views = array( 226 ); // Edit to add IDs of Views to add this to

    if ( in_array( $view_id, $target_views ) ) {
  
        // if there is a search term set
        if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
            $query_results->posts = array();
            $query_results->post_count = 0;
            $query_results->found_posts = 0;
        }
    }
  
    return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );

You will need to delete the text for "No items found" from the View.

#1351801

Hi Nigel

I have done this, but still the same result. Anything else I need to check or change?

Regards,

#1351819

Nigel
Supporter

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

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

No. You remembered to edit the View ID?

I tested the code on my own site with a similar set up using automatic pagination and it works as expected, so it should work on your site.

#1352155

Dear Nigel

It seems as it is working, when I put the code in "Appearance, Theme Editor -> functions.php

I am not sure what the big different is, but if You can clear that with me, would be great.

Regards,

#1352435

Nigel
Supporter

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

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

I suspect when you added the code in the Toolset settings you didn't activate the code snippet?

There is little practical difference between adding the code in Toolset settings vs. editing your theme's functions.php file, except it is supposed to be more convenient ( 🙂 ) and means the code isn't lost if you change theme.

But the important thing is whether the code works, and it sounds like it does, yes?

Sorry it took a while to get to the solution, the other method should be simpler, but it can't work very easily with your View that has automatic pagination.

#1353415

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.