Skip Navigation

[Resolved] Display only Filtered Values

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

Problem:

I have a custom search which filters by post ID based on URL query.
Right now for an empty query the view returns all results.

Is there a way to return the [wpv-no-items-found] bit intstead for this particular view?

Solution:

f you pass empty URL parameter "my-url-param" to view, view will output all result.

In your case, you can change it with Views filter hook "", for example add below codes into your theme/functions.php:

add_filter( 'wpv_filter_query', 'show_empty_default_func', 99, 3 );
      
function show_empty_default_func( $query_args, $setting, $view_id ) {
    if($view_id == 12345)
    {
        if( isset($_GET['my-url-param']) && $_GET['my-url-param'] == '' ) 
        {
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

Please replace 12345 with your view's ID, replace "my-url-param" with your URL parameter

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#640630

Hi,

I have a custom search which filters by post ID based on URL query.
Right now for an empty query the view returns all results.

Is there a way to return the [wpv-no-items-found] bit intstead for this particular view?

Thank you

Adrian

#641028

Dear Adrian,

If you pass empty URL parameter "my-url-param" to view, view will output all result.

In your case, you can change it with Views filter hook "", for example add below codes into your theme/functions.php:

add_filter( 'wpv_filter_query', 'show_empty_default_func', 99, 3 );
     
function show_empty_default_func( $query_args, $setting, $view_id ) {
    if($view_id == 12345)
    {
        if( isset($_GET['my-url-param']) && $_GET['my-url-param'] == '' ) 
        {
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

Please replace 12345 with your view's ID, replace "my-url-param" with your URL parameter

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#641043

Hi Luo,

Thank you for your suggestion. I will try that out soon.
In the meantime, I was able to add a redirect for that specific slug, which only impacts the default URL. If an ID is passed via URL string, it no longer redirects.

Very primitive, I know but does the trick for now. I will try your solution as well in future versions and I will post back here if I have any issues implementing it.

Thank you

#641373

You are welcome

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