Skip Navigation

[Resolved] Previous Support Reply Doesn't Work

This support ticket is created 2 years, 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by j.-michaelA 2 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2540275

Tell us what you are trying to do?
On 12/9/2022, Waqar sent me the following snippet to solve a filter issue I submitted on 12/8/2022:

// Source URL: https://toolset.com/forums/topic/setting-up-a-condition-in-a-view/#post-2514261
add_filter( 'wpv_filter_query', 'wpv_filter_query_custom_func', 1000 , 3 );

function wpv_filter_query_custom_func( $query_args, $view_settings ) {
// process if View 23249 'Report Test 2'
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 23249 ) ) {
// get current user login name
$current_user = wp_get_current_user();
$current_user_login = $current_user->user_login;
$target_custom_field = 'stu-pd-username';

if(!empty($current_user_login)) {
$query_args['meta_query'] = array(
'relation' => 'AND',
'date_field' => array(
'key' => 'wpcf-'.$target_custom_field,
'value' => $current_user_login,
'type' => 'CHAR',
'compare' => '=',
),
);
}
}

return $query_args;
}

We recently realized that, when added to our functions.php file, it does filter the view block so that the logged in user only sees custom posts where the custom posts are those belonging to the logged in user. However, when we do so, the other search filters in the view block become totally disabled. Please help so that your filter solution will not disable all other search filters for that view block.

Thank you.
Mike

Is there any documentation that you are following?
We have review all the related Toolset courses and documentation.

Is there a similar example that we can see?

What is the link to your site?
dev.abfse.org

#2540411

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I'm not sure what is you problem URL and where you added your view. Can you please share problem URL and admin access details and let me see whats going wrong with your setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2541141

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing all required information but unfortunately the frontend user access details for user "user102" you shared is not working at this end. I tried to change the password as well from admin but still somehow its not allow me to login from the frontend and I get error "Your username or password was incorrect": hidden link

Can you please send me working access details for the frontend user: "user102"

I have set the next reply to private which means only you and I have access to it.

#2541735

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've selected your view and turn off the setting "Show only filter options that would produce results" form your view blocks "Custom Search" settings as you can see with the following screenshot: hidden link

Do you see it working as expected now?

#2541821

Minesh,

The search is not working as expected. I get the correct list of Students posts. However, the View Search block at the top of the View (Last Name, Student ID, etc.) does not work when the custom function is in place. The logged in person needs to be able to search their listed Students posts.

Mike

#2541831

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry - the code that is shared by waqar is to list only posts where your custom field stu-pd-username value is equal to current loggedin user. Is this not the requirement?

Can you please tell me what exactly not working. Maybe you can share video or what is your expected result when we search with what keyword with what field.

#2541855

Minesh,

The view at hidden link does show a list of only those students who belong to the logged in visitor. However, if you login and go to that Test 2 view, you will see that now the View Search block fields at the top of the report are no longer working. If you enter anything in any of the search fields and click the Submit button, nothing happens. Those search fields work correctly if Waqar's function is removed. However, then, you no longer have a list of only the logged in user's Student custom posts.

Please try it an you will see that the search fields no longer work when the function is in place.

#2541871

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've only read only file permissions so I could not able to edit the code added to the functions.php file.

Can you please send me FTP access details so that I can edit the code added to functions.php file.

I have set the next reply to private which means only you and I have access to it.

#2541887

Minesh,

I am not able to grant FTP access. However, I have changed the file permissions for functions.php to RW-RW-RW- (666). You should now be able to download the download the file to make any changes. If you need me to send you a copy of the file or to upload the file after you make your changes, please send me instructions.

Thanks,
Mike

#2541889

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've removed the code added to the functions.php file and added to the "Custom Code" section offered by Toolset and adjusted it as given under:
=> hidden link

add_filter( 'wpv_filter_query', 'wpv_filter_query_custom_func', 1000 , 3 );
function wpv_filter_query_custom_func( $query_args, $view_settings ) {
    // process if View 2324 'Report Test 2'
    if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 2324 ) ) {
        // get current user login name
        $current_user = wp_get_current_user();
        $current_user_login = $current_user->user_login;
        $target_custom_field = 'stu-pd-username';
 
        if(!empty($current_user_login)) {
            $query_args['meta_query'][] = array(
                'relation' => 'AND',
                   'date_field' => array(
                    'key' => 'wpcf-'.$target_custom_field,
                    'value' => $current_user_login,
                    'type' => 'CHAR',
                    'compare' => '=',
                ), 
            );
        }
     }

    return $query_args;
}

Can you please confirm it works as expected now.

#2541925

Minesh,

Thank you so much for your patient assistance with this issue. I really appreciate your prompt follow-up.

I spent a great deal of time trying to resolve the issue on my own. I now see what I was doing wrong and the proper way to implement custom functions within Toolset.

My issue appears to finally be resolved.

Thank you again!
Mike