Skip Navigation

[Resolved] Reset button parameter

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

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
#2231951
url 2.png
url 1.png

Tell us what you are trying to do?

I have built a view with a custom post type displaying news. This CPT is associated with some selected custom taxonomies such as 'type of news', 'subject of news' and 'branch' (=economic sector). All of these taxonomies are displayed in the search section as front-end filters, together with some other filters such a 'text search' using relevansi and a search for a date range.

I have defined in the content selection of the view , that CPT's are selected based on the taxonomy 'branche' using a url parameter (query filter) (see screenshot 1).

So if I use the url 'hidden link', the view will show only the CPT's associated with the taxonomy term 'aph' from taxonomy 'branche', i.e. only 88 news are displayed instead of the total of 302. Perfect.

So far so good, BUT: I am using the SEARCH FILTER BUTTON and the RESET BUTTON in the search section (see screenshot 2). If I use some filters in order to search for specific information, and then I cklick on the RESET button to reset all filteres, the view will fall back to ALL or the TOTAL of news (302), instead of 88 news and staying within the boundaries of the preselected filter (aph).

The RESET button should establish again the orginal url with filter
hidden link'

but RESET leads to the url hidden link

How can I achieve, that RESET button will fall back to the total of the preselected CPT's and not to the total of all CPT's?

P.S. I deleted the front-end filter 'branche', thinking that this would change the behavior of the RESET button. But nothing changed...

Is there any documentation that you are following?
https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/

Is there a similar example that we can see?

What is the link to your site? s. above, the views can bei accessed only after login...

#2232107

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The normal behavior of Reset button is it will reset all the filter values to default values and that is how it works there is no way to track what filter should be keep applied when you click on Reset button.

If you want to prefilter the view result based on the taxonomy term "aph" - we an do that but then when you load the view on frontend it will display prefilter view with 88 news are displayed by default.

#2232381

Hi Minesh,

many thanks for your answer. Yes, I would be interested to prefilter the view based on the taxonomy term selected, if the filter default value can be selected dynamically. Is it possible to adjust the default filter value based on, f.ex., the url parameter, which determines, which taxonomy term of 'branche' is selected, i.e. can the default filter value be determined by the same url parameter?

wpv-branche=aph => default value in filter 'select taxonomy term of 'branche' = aph
wpv-branche=bh=> default value in filter 'select taxonomy term of 'branche' = bh
etc.

Would that be possible? Using a filter function? I am working with the block-editor, I don't see, where I can pass a default vaue to the filter. Or do I have to change to the legacy editor?

Kind regards
Franz

#2232755

Hello Minesh,
in the meantime, I defined the html code

<p>[wpv-control-post-taxonomy taxonomy="branche" type="checkbox" default_label="Ihre Branche" format="%%NAME%% (%%COUNT%%)" output="bootstrap" url_param="wpv-branche"]</p>

I defined a custom search filter which I placed in the search section of the view using a html-block. I tested the view, using an url with the argument ?wpv-branche=aph. Opening the view with this url, the view just displays 88 custom posts belonging to that taxonomy, and the filter just displays the selected taxonomy term, so that's ok. But when I click on the reset button, the view again falls back to the total of all posts instead of the total belonging to the selected term. I guess, I should define the default value (which ist the url_param, but i don't know how..

Kind regards

Franz

#2233263

Minesh
Supporter

Languages: English (English )

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

That is what I already communicated that when you click on the Reset button it will remove all the filters and view will be reset back to its original state without having any filters.

If you want to prefilter the view results even when you click on the "Reset" button you will have to use the view's filter "wpv_filter_query" to filter to view results but then you will have to tell me what will be the default state or with what term you want to pre-filter the view results.

Can you please share admin access details and confirm with what term you want to prefilter the view results.

*** 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.

#2235195

Minesh
Supporter

Languages: English (English )

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

As I understand - now what you want is when I loggedin as testaph, and when I try to click on menu item "'Meine News'", it should redirect me on:
- hidden link

And when I loggedin as testbh and when I try to click on menu item "'Meine News'", it should redirect me on:
- hidden link

Correct?

If yes, then we can workaround it by using the some filter hook to change the link per user for the menu "'Meine News'" as that will be more feasible. As waqar shared, we can prefilter the view using the hook "wpv_filter_query" that I already mentioned with my previous reply:
https://toolset.com/forums/topic/reset-button-parameter/#post-2233263

But prefilering the results will also involve additional things of adjusting the filter option for dropdown and that is double work but if we can chose route to change the menu item link per user it will be more efficient.

I would like to know with what user you want to set what links? I mean I know you already shared two users, but to make it dynamic I would like to know for what users you want to set what. Do you want to set the dynamic filter option based on user or based on user role?

#2235285

hello Minesh,

the first 2 remarks in your post are very correct, that's exactly what I want. I made a mistake and defined the branch front-filter as dropdown, but I corrected that and changed to checkboxes. That's better, because if a user clicks on the 'Meine News' menu using the url argument, there will remain just one position, i.e. the branch term selected. And the checkbox itself, I will hide with specific CSS, so the user cannot return to 'all'.

Your second question: I would like to set dynamic filters based on user roles. We have about 14 user roles representing 14 branches, each branch containing about 5-30 users. I assign roles and access rules to users with AAM plugin (much more granular compared to Toolset access, that's way I am working with AAM). So all users belong to a role corresponding to the branch, where the user comes from.

Kind regards

Franz

#2235835

Minesh
Supporter

Languages: English (English )

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

Can you please share information that based on what role you want to configure what URL param?

#2235929
5 User roles testaph.png
4 Organization role z-baerau.png
3 Branche role APH.png
2 Taxonomy slugs branche.png
1 Taxonomy terms branche.png

hello Minesh,
so the approach for url parameter is always the same:

hidden link

In screeshot 1 you can see all the branch taxonomy terms as they are displayed in the front-end filter. These taxonomy terms correspond to the branch taxonomy terms defined at the backend, see screenshot 2.
hidden link

And the slugs of these terms (screenshot 2) correspond exactly to the user roles, and they are used as such in the url-parameter: ?wpv-branche=bh is ?wpv-branche='slug of the branch taxonomy term'. So you can just use the slugs of screenshot 2:

f. ex. slug = pm, url parameter is: ?wpv-branche=pm, and this will be the redirect of user role PM (by the way, I have not yet set the redirects for all user roles, should I do it?).

Just a additional remark, maybe that's important, if you work with user roles: we use multiple user roles:

- each user has first a 'branch role' defined as described above (screenshot 3). The 'subscriber role' (Abonnent) is parent of the 'branch role'. This 'branch role' has been defined just for the news view, we are talking about, because the news are displayed to users depending on their branch (economic sector).

- each user has then a second role, called 'organization role', which is just a abbreviation of his organization name, where he comes from. This is important for a second query on our website, which displays a list of legal documents, which are specific for a organization. 'Branch role' is parent of 'organization role' (screenshot 4).

So each user has 2 roles, a 'branch role' (f.ex. APH) and a 'organization role' (f.ex. z-baerau), as illustrated in screenshot 5 for user 'testaph'. If this multiple role construct is a problem for your workaround, let me know.

#2235995

Minesh
Supporter

Languages: English (English )

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

I've added the following code to "Custom Code" section offered by Toolset with the code snippet "toolset-custom-code":
=> hidden link

function update_menu_link($items){
global $current_user;

        foreach($items as $item){
            if($item->title === "Meine News"){ 
              $role = $current_user->roles[1];
                $item->url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/gesetzesportal/news/?wpv-branche='.$role ; 
            }
        }
        return $items;
}
add_filter('wp_nav_menu_objects', 'update_menu_link', 10,2);

Now, we are replacing the URL with dynamic role of current user. Can you please check this is what you were looking for.

#2236087

hello Minesh,

many thanks for your code. Something is not working as it should do, If I log in with user testaph and click on my news, than the url will be

hidden link

that means that the slug or the role term is missing! And correspondingly, in the view the taxonomy term belonging to the user is not activated.

I think, this problem can be explained by the user role function. I tried several times to use this function, but never got the role string or value back. It seems to me (with my very restricted know-how), that this function is not working as it should.

What do you mean?

Kind regards

Franz Gasser

#2236145

Minesh
Supporter

Languages: English (English )

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

I got the issue.

The thing is that when I logged-in using the user "testph" the role slug was available at roles array index 1.

$role = $current_user->roles[1];

Now, when I logged in as "testaph" user the role slug was available at roles array index 3. So that means the role slug/name will be available at any index.

What you have to do it you will have to find the way so that you should query all terms and and then once you get that you should find the matching role from your found terms array and current user roles array and then once you find the match you should assign that match to $role.

I tried to use get_terms() to get all terms from "branche" taxonomy but I'm not sure whats going on with your setup it only return 2 terms. If you help me to get all terms from taxonomy "branche" I can do it for you or otherwise we need to make a static array with all available "branche" taxonomy terms slug and then we can take next steps.

#2237377
User roles.png

hello Minesh,

many thanks for the update. So I defined now for all taxonomy terms 'branche' the redirect for 'Meine News' as described above, and I tested the login for all test users representing all branches.

Then, I defined the roles for the test users, and as you can see in the screenshot, the role 'branche' is always at the first place, the role 'organisation' is on the second place. So in this way, you can hopefully get the current user role.

So, if that does not work either, I could for some users eliminate the second role just in order to test your function with just one user role. In the worst case, I can select another approach to define the user roles, in this case.
Kind regards

Franz

#2237691

hello Minesh,

I had to inactivate your custom code, because I had some access problems with users. I deleted for one user one of the 2 roles, and then your code perfectly returned the remaining role term, but not the right one for the news. So please let your code as it is now, and I think about another concept with just one user role I will contact you again in a few days.

Kind regards

Franz

#2237895

Minesh
Supporter

Languages: English (English )

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

Ok fine.