Skip Navigation

[Resolved] How to reuse view+map and variants of it

This support ticket is created 2 years, 10 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 10 replies, has 2 voices.

Last updated by Arno 2 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#2345151

Hi,

I have created a view and a map that basically work fine as long as I am logged into the website. I have a few issues left though:

1. The map is inside a conditional block because it needs to be rendered only to authenticated users. That works, but there is a problem with the view in a Chrome incognito tab: the custom search filters do not filter the posts, and after the failed search the filter dropdowns are empty. I wonder if it's because of the conditional map or if there's another reason.

2. How do I insert the view and map into multiple pages, while still having one place to make changes to it? I tried to put them in a reauseable block but the conditional blocks lost their rules configuration. Should I create a Toolset template for this, not related to any post type, and insert this template in other pages? What's the best way?

3. Same as 2, but what if I need the view+map somewhere else with one of the filter dropdowns set to one of the options by default on page load? For example: the view lists "all towns" and has a search filter for regions. Now I need the same view but with the regions filter already set to one of the regions. How do I set the default value? How to I prevent creating an entirely new view for this?

This is the page with the view and map:
hidden link

I can give you access to the backend if needed.

Thanks,
Arno

#2345271

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Arno,

Thank you for getting in touch.

1. The map is inside a conditional block because it needs to be rendered only to authenticated users. That works, but there is a problem with the view in a Chrome incognito tab: the custom search filters do not filter the posts, and after the failed search the filter dropdowns are empty. I wonder if it's because of the conditional map or if there's another reason.

This occurs because your search filter doesn't have any reset button. What happens is when you filter your search. The search bar will only present the a value that can be used to filter the current results. There are 2 ways to resolve this.

1. You can add the reset filter button which would reset the search.
2. You can set the filter to display all the values rather than only the values that will produce a result on the search. To do this you will need to select your view block and then go to the custom search settings tab on the right and toggle off "Show only filter options that would produce results"

2. How do I insert the view and map into multiple pages, while still having one place to make changes to it? I tried to put them in a reauseable block but the conditional blocks lost their rules configuration. Should I create a Toolset template for this, not related to any post type, and insert this template in other pages? What's the best way?

If your conditional is in the view block as well as with the map then you can simply go to your new page and add the view block. You can also create a content template as you say and then load it onto the page.

This is perhaps the best way to approach this since the content template is self contained.

3. Same as 2, but what if I need the view+map somewhere else with one of the filter dropdowns set to one of the options by default on page load? For example: the view lists "all towns" and has a search filter for regions. Now I need the same view but with the regions filter already set to one of the regions. How do I set the default value? How to I prevent creating an entirely new view for this?

This will perhaps require some amount of custom code to achieve if you don't want to create a duplicate view with this slight change. So what you will need to do is to use our View Query filter hook to set the specific custom field query value when the page is loaded.

It will essentially be dependent on the page ID to determine if the view should be prefiltered.

Thanks,
Shane

#2345361

Thank you Shane!

1. I'm afraid this is caused by something else. Yes, I do use "Show only filter options that would produce results" and I am aware that filter options disappear based on other selections. However, the frontend filtering is not working at all and dropdowns are completely empty after attempting a search. Please see hidden link. However, when logged on it's all fine.

2. Ok, content templates it is.

3. I want to avoid custom coding at all costs. So I guess I need to create a view for each variant. An example is the view of point 1, which has a Town filter. I want the variant view to be exactly the same, except that the Town dropdown should already have selected one of the towns on page load, and the view output should of course list results based on that. I tried to change the view query filters and did this: "Select posts with taxonomy: Towns in one of these:


Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Arno,

Would you mind allowing me to have admin access to the site to have a look at the filter issue for this view?

Secondly for your variant will this be constant? Meaning the town value won't change at all ? So the user will be able to filter the options from that specific town ?

Please let me know.
Thanks,
Shane

#2345749

Hi Shane,

No problem, here's the access link: hidden link

The view is in the template "View Travel guides-Search-Frontend", which is used on the page "Travel guides Switzerland". The view has a Towns filters.

What I have in mind is creating a variant of that view, with a fixed town pre-selected in the dropdown. Users should still be able to pick a different town, hit the search button and get different results.

In general the question is how to set a default value for one or more search filters, in order to have a specific view output on page load, but allow the user to make changes and tweak the results to fit their needs.

Kind regards,
Arno

#2346169

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Arno,

I was able to see the issue at hand and it appears to be caused by the filter settings itself where the option to only display values that will display a result is enabled. When I disabled this option the filter options show up fine.

What I have in mind is creating a variant of that view, with a fixed town pre-selected in the dropdown. Users should still be able to pick a different town, hit the search button and get different results.

In general the question is how to set a default value for one or more search filters, in order to have a specific view output on page load, but allow the user to make changes and tweak the results to fit their needs.

Based on your request here i'm assuming that you still want the town filter to be useable. In this case only through the use of custom coding will this be possible because we can set a static value but then this value you won't be able to change on the frontend.

So our option here is to specify the preselected value using our Views filter Hook.

Thanks,
Shane

#2346245

Hi Shane,

Is your first comment about issue #1? That was about the filters not working at all for anonymous visitors. I suppose that should work regardless of the option to only display values that will display a result.

As for issue #3: I need to avoid custom code, so I will need to think of an alternative. Are you saying that if I need to "pre-filter" on a specific town, the view can't have a frontend town filter at the same time? It's either a query filter in the view OR a frontend filter set to nothing initially?

Thank you,
Arno

#2346483

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Arno,

Given that the issue only occurs when the user is logged out then it is not a normal use case. The functionality should be the exact same as with logged in users.

At this point I would recommend that you temporarily disable all the non-toolset plugins and then check the search on the frontend again to see if the issue still remains.

As for issue #3: I need to avoid custom code, so I will need to think of an alternative. Are you saying that if I need to "pre-filter" on a specific town, the view can't have a frontend town filter at the same time? It's either a query filter in the view OR a frontend filter set to nothing initially?

The only other alternative to custom code that I can think of is to pass the value of the city/town that you want to be prefiltered into the URL. Basically our view is filtered by a URL parameter value so if we pass the city value in the URL then it should pre-filter the view.

This is assuming that the link that you're clicking is possible to add the URL parameter to it.

Thanks,
Shane

#2346827

Hi Shane,

#1 I disabled plugins as you recommended and found that the issue went away when PublishPress Permissions was disabled. For now I have simply deleted this plugin and will deal with this later. The filters work fine now for anonymous users.

#3 URL parameters are not acceptable for this project. I will settle for not having a frontend filter for whatever I am filtering for in the view query: if I filter for particular towns in the view query it works fine as long as I don't also put a custom search filter for the Towns taxonomy in the view. It's one or the other apparently. For this particular example it's not a big deal.

Kind regards,
Arno

#2347097

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Arno,

Thank you for the updates. Happy to see that the conflict with the search filters have now been resolved.

I must apologize for not being able to provide a suitable solution for your second issue.

If there are no further questions you can go ahead and mark this ticket as resolved when you're ready.

Thanks,
Shane

#2347107

Thanks Shane!