Skip Navigation

[Resolved] display only filtered results

This support ticket is created 4 years, 1 month 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 – 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: Africa/Casablanca (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 4 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1888115
Screenshot 2020-12-28 at 12.25.50 AM.png

Dear Sir/Madam,

I want to return nothing if there is no parameter "cmid" passed, I refer to the solution from https://toolset.com/forums/topic/display-only-filtered-values/ but I can't do the same.

Here is the code

if ($_SERVER['REMOTE_ADDR'] == '14.198.104.144') {
    add_filter( 'wpv_filter_query', 'fn_show_empty_result', 99, 3 );
}
 
function fn_show_empty_result( $query_args, $setting, $view_id ) {
    
    if ($view_id == 2181) {
        if( isset($_GET['cmid']) && $_GET['cmid'] == '' ) {
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

It shows all result without filtering if there is no cmid parameter included in URL, what is the problem to my code?

Best regadrs,

Kelvin.

#1888139

Hello Kelvin and thank you for contacting the Toolset support.

To better assist you with this issue, I'll need to take a closer look at the view in the frontend to check if the URL parameter is 'cmid', the view_id is 2181.

But, I wonder why using the filter on condition:

if ($_SERVER['REMOTE_ADDR'] == '14.198.104.144') {
    add_filter( 'wpv_filter_query', 'fn_show_empty_result', 99, 3 );
}

Would you allow me temporary access to check this further? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1892897

Dear Jamal,

I solved my issue by changing the code with below code

function fn_show_empty_result( $query_args, $setting, $view_id ) {
    
    if (in_array($view_id, array(2181, 2006))) {
        if(!isset($_GET['appid']) || $_GET['appid'] == '' ) {
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

I change the cmid to appid for better variable naming.

I use

$_SERVER['REMOTE_ADDR'] == '14.198.104.144')

because I want to do some debug but I am not sure whether wpv_filter_query is the best filter for my case. Please advise.

Best regards,

Kelvin.

#1893033

Hello Kelvin,

I am glad you fixed the custom code.

The wpv_filter_query allows to customize the view's query. If you use it inside that condition, it will only be applied when the condition is met.
But, I am not sure what debugging you are talking about. Keep in mind that Toolset Views do have a debugging mode that generates a popup, only for administrator users, with more details about the views, content templates, or archive templates that are used in the currently visited page. Check this article's section https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#the-views-debug-tool

I hope this helps. Let me know if you have any questions.