Skip Navigation

[Resolved] Reset button parameter

This support ticket is created 2 years, 12 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 22 replies, has 2 voices.

Last updated by franzG-4 2 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2238227

Hello Minesh,
I copied your custom function with the name 'redirect-to-user-role-gesetzesliste`' and related this code to another view 'Gesetzesliste' on our website, where the second user role 'organisation' is important for selecting the items:

------------------------------------------------------------------------------------------
function update_menu_link($items){
global $current_user;

//look through the menu for items with Label "Link Title"
foreach($items as $item){
if($item->title === "Meine Gesetzesliste"){
$role = $current_user->roles[1];
$item->url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/gesetzesportal/gesetzesliste/?wpv-organisation='.$role ;
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'update_menu_link');
------------------------------------------------------------------------------------------

I modified the settings of 2 users, so that they have only one user role:

username: jasminstu, PW dAMUedANA8

When I deactivate the your custom function, the redirect hidden link (teufen ist the user role) opens the preslected view with about 198 items instead of the total of 2'080 items. But as discussed earlier, if I press the RESET button, all items will appear, which is not admissible.

If I activate your code, then all items are displayed, not restricted. The url is
hidden link

so the user role is missing. Something is not working with the code. However now, with just one role for this user, his role is displayed just above the view, which was not the case, when we had 2 roles for this user. That means the user role is really returned.

The second user is username stphangerosa , PW capAXm4Zryx7&Ecy1fGuhh@a, user role is 'aba', same situation as described above.

Would it be possible to optimize the code so that user role appears in the url?

Kind regards
Franz

#2238757

Minesh
Supporter

Languages: English (English )

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

I've adjusted the code as given under to the "Custom Code" section with the code snippet 'redirect-to-user-role-gesetzesliste'. The code is adjusted as there will be only one role assigned.

function update_menu_link($items){
global $current_user;
  
  //look through the menu for items with Label "Link Title"
        foreach($items as $item){
            if($item->title === "Meine Gesetzesliste"){ 
              
              $x = array_merge(array(),$current_user->roles);
              if(count($x) == 1){
              	$role = $x[0];
              }        
              
                $item->url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/gesetzesportal/gesetzesliste/?wpv-organisation='.$role ; 
            }
        }
        return $items;
}
add_filter('wp_nav_menu_objects', 'update_menu_link');

I see now the link is populated correctly:
=> hidden link

#2238785

hello Minesh,

many thanks for your effort, that works great. However, the problem of resetting the view is not resolved (reset will still display the total of all view items, and not the total of the selected organization)? So that means, that this workaround does not help with the reset problem?

I tested yesterday the code of Waqar (mentioned earlier) for the preselection of taxonomy terms (pre-get query). This works fine, but then, the front-end filtes cannot be used anymore (or only after a quite complicated programmatic adaption of those front-end filters). Do you have any experience with that, or do you recommand another approach?

Kind regards
Franz

#2238825

Minesh
Supporter

Languages: English (English )

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

many thanks for your effort, that works great. However, the problem of resetting the view is not resolved (reset will still display the total of all view items, and not the total of the selected organization)? So that means, that this workaround does not help with the reset problem?
==>
I would like to know, do you want to reset only the "organisation" filter or you want to reset all the filters. As acknowledged before the solution I shared will help you to set the role as per the current user login to your menu and when you click on that menu user will see the filtered results. Toolset "Reset" button is set to reset all the filters irrespective of any filters. You can now control that you can still want to apply or keep one filter when you click on "Reset" button. "Reset" mean it will reset all the filters.

I think we can use the "wpv_filter_query" but now when I try to login as the use you shared "jasminstu" I can not access the URL:
=> hidden link

it shows me the following message:

Sie haben keinen Zugriff auf diese Seite

Can you please allow me access and let me try to add the "wpv_filter_query".

#2238869

hello Minesh,

sorry for that, access should be possible again. I was working with my staff on the website, maybe this was the reason. I testet the login and access with this user, everything was ok.

Kind regards

Franz

#2238875

Sorry, I did not look at your question about filtering, So what I would like:

1. When a user logs in, then the view will show the items corresponding to his role 'organization'. This is a fixed prerequisite, and further front-end filtering for the taxonomy 'organisation' is not required.
2. There are 2 additional drop-down filters called 'Kanton/Land' and 'Gesetzesindex', both representing a taxonomy, and a filter for the selection of a date range.

a) It should be possible to use these 3 filters, even when the taxonomy 'organization' is preselected
b) Reset button action should reset all 3 filters, but not taxonomy/filter 'organization.

Kind regards
Franz

#2239017

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've added the following filter code to the "Custom Code" section offered by Toolset:

function func_apply_default_term_filter( $query_args ,$view_settings, $view_id ) {
   global $current_user;
     
   if ( $view_id == 7443 and !isset($_GET['wpv-organisation'])) {
      
      $x = array_merge(array(),$current_user->roles);
       if(count($x) == 1){
              	$role = $x[0];
       }        
      
       $query_args['tax_query'][] = array(
            'taxonomy' => 'organisation', // taxonomy name
            'field' => 'slug',
            'terms' => array($role), // term slug for exclude
            'operator' => 'IN'
        );
        $query_args['tax_query']['relation'] = 'AND';
         
    }
    return $query_args;
}
add_filter( 'wpv_filter_query', 'func_apply_default_term_filter', 10, 3);

The above code will help you to filter the view by default with the current user role that is your organization taxonomy term.

Then to set the default option selected for dropdown organization filter I've added the following line of HTML to your view's "Suche und Seitenumbruch" section.
=> hidden link

<input type="hidden" name="current_role" id="current_role" value="[wpv-current-user info='role']" />

And then added the following JS to js box of your view:

current_role = jQuery("#current_role").val();
    jQuery('select[name="wpv-organisation"] option[value='+current_role+']').attr('selected',true);

Can you please confirm it works as expected now.

#2239349

My issue is resolved now. Thank you!