add_filter('frm_where_filter', 'my_unique_name_filter_custom_display', 10, 2);
function my_unique_name_filter_custom_display($where, $args){
$view_id = bsn_get_post_id_from_slug('slug-of-view'); // replace 'slug-of-view' with your view slug
$field_id = bsn_get_field_id_from_key('field-key'); // replace 'field-key' with your field's key
if ( $args['display']->ID == $view_id && $args['where_opt'] == $field_id){
$user_id = $_GET['trainer']; // change trainer to the name of the parameter in your URL
if ( !is_numeric($user_id) ) {
// if the username was in the url, get the ID
$user_id = FrmProAppHelper::get_user_id_param($user_id);
}
if ( is_numeric($user_id) ) {
$where = ("meta_value = ". $user_id ." and fi.id='". $args['where_opt'] ."'");
} else {
// no matching user ID was found
$where = ("meta_value = 1 and meta_value = 0 and fi.id='". $args['where_opt'] ."'");
}
}
return $where;
}
if (!function_exists('bsn_get_post_id_from_slug')) {
function bsn_get_post_id_from_slug($slug) {
global $wpdb;
$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$slug'");
return $id;
}
}
if (!function_exists('bsn_get_field_id_from_key')) {
function bsn_get_field_id_from_key($field_key) {
global $frmdb, $wpdb;
$field_id = $wpdb->get_var("SELECT id FROM $frmdb->fields WHERE field_key LIKE '".$field_key."'");
return $field_id;
}
}
Hi Darryl,
I'm trying to use your code to filter a view by userid passed from the URL. I have set as following:
URL: http://intranet.beehives.de/frm_display/show-all-expenses/?empname=5
slug-of-view: show-all-expenses
field-key: the key of the hidden USERID Field
trainer: empname
With these settings, it is still showing me all entries instead of the entries just of the user specified in the URL. Do you have any ideas what I might be doing wrong?
It may be that there's something wrong in my helper functions, $frmdb has been deprecated since this was written, and there have been other changes to Formidable Pro.
Try hard-coding the IDs and removing the references to the helper functions.
Like: