Skip Navigation

[Resolved] Showing search form if user position is not available

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.

Our next available supporter will start replying to tickets in about 2.11 hours from now. Thank you for your understanding.

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 9 replies, has 2 voices.

Last updated by nicolaS-3 1 year, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2571959

Hi all,
I have a classic view that works fine where I use distance from user position to filter content and sort posts by distance ascending (of course all posts have an address). Posts also have a Geo (region/province) hierarchical taxonomy associated. When the users hasn't activated its position tracking the view shows all post unsorted and this is no good. In this case I would like to show a search form to filter posts by region/province.
I am struggling to find a way to show the form only when the user hasn't activated it's position tracking so that Toolset Maps can't calculate the distance. I have also created another simple "service" view that queries the distance and returns nothing if the first post distance can't be calculated or whatever number if the distance can be calculated, but I actually don't know how to test this inside the main view... Any suggestion ?
Thanks
Regards
Nicola

#2572033

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You can always use the [wpv-conditional] shortcode in order to display content conditionally.
=> https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

But in your case you would like to add a form but what form you want to display are those filters belongs to same view?

I will have to review your current structure and you can share problem URL with me and please share step information on that instance you want to display what form with what filters and then I will be able to guide you in the right direction.

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

#2572653

Minesh
Supporter

Languages: English (English )

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

So what if you create another view with the taxonomy filter and add that view that displays the map:
=> hidden link

And add that view with the section:

[wpv-no-items-found]
<p style="text-align:center;color:red;">Non è possibile mostrare la mappa poichè non sono stati trovati elementi corrispondenti ai filtri impostati. Rimuovere i filtri per mostrare la mappa generale.</p>
	[/wpv-no-items-found]

Does that makes sense?

Or another idea is:
- Create a another view with taxonomy filter
- add a new page and add the above newly created view to this page
- add the link of this page to [wpv-no-items-found] section with instructions that there is no result to display in this location so you can explore result on another page.

#2572757

Hi,
the idea to use [wpv-no-items-found] is smart, but unfortunately not applicable. Let's assume there are 10 posts (out of 500 total posts) showing within the distance range when the distance filter is on. Those 10 posts will still exist when the distance filter is off and will show mixed within the other 500 in unsorted order. The [wpv-no-items-found] will never happen. What I need is a test to know which of the two views to show.

#2572761

Minesh
Supporter

Languages: English (English )

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

I will require few test examples with problem URL where I can use XXX address that should display the results.

And I think there is no need for another view then and lets investigate what issue you have with the those 10 results.

Can you please share step by step information and problem URL where I can test this and with what address I can see 10 results and what is the issue you have with those 10 results and what next steps I will have to follow (apply any other filter) to see the problem and what is your expected results.

#2572787

Before going through the "real thing", please have a look to the test page named aaa turning your position tracking on and off in your browser. I entered two conditionals to test the temp-distanza view output that is supposed to return OK if distance can be calculated (by the view output above on the same page) or NO if it can't be. It seems to be working when it's positive, but not when the position tracking is off: the view returns empty but the test still returns OK ... I don't understand why. In the conditions I had to select STATIC VALUE to enter the condition (ot sure if this is correct though).
I have added two fake pubs called Pub1 and Pub2 in the Pubs CPT for you with random addresses in Ahmedabad in order to let you have some posts close to your position, feel free to change them so that you can see them when the position tracking is active. With the traking off you should see all 430 pubs including the two fake pubs associated to the Abruzzo/Chieti Geo taxonomy.

If this test would work I'd replace the OK/NO with the appropriate views.
Thanks

#2573363

Minesh
Supporter

Languages: English (English )

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

I can see now "No items found" when there is no posts available within the distance range specified.

In the view output you have to wrap the shortcode with [wpv-geolocation]:

[wpv-geolocation message_when_missing="We need your location to show this content"]
[toolset-maps-distance-value origin_source='visitor_location' postmeta='wpcf-pub-address']
[/wpv-geolocation]

I've also added the distance query filter:

Distance
Show posts within 5km radius of the viewing user's location.

Because if distance query filer is not added it will not work properly.

#2574205

Hi Minesh,
sorry but this doesn't seem solve my issue. You got no-items-found just because you used a very small radius (5 km), actually in a real situation with many posts (500+) it will never happen to get into the no-items-found.

I just need to test if Toolset is able to calculate the user's distance from an address (browser position tracking on) or not (browser position tracking off). In the first case the temp_distanza view will return a number in the second nothing/blank. It doesn't matter at this stage if the result is within a distance range or not, that will be used later in the appropriate view shown to the user (with or without the form).
The issue is in the conditionals on the aaa page: they test if the temp_distance view returns a number of an empty/blank, but both conditionals fail. The only reason I can see could be that the view returns "something else" instead of empty/blank. So I deactivated the wrapping div and the position tracking in the browser then inspected the HTML. It seems that the view correctly outputs nothing/blank so why does the tests fail ? Any idea ? thanks

#2574281

Minesh
Supporter

Languages: English (English )

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

The conditions were failing because somehow even the view returns empty results it returns white spaces.

To overcome that I've added custom shortcode to "Custom Code" section offered by Toolset with code snippet "trim-view-output":
=> hidden link

add_shortcode( 'trim_view', function($atts){
    
  $content = trim(render_view( array( 'name' => $atts['name']) ));
   
  return $content;
});

Then I've register the above custom shortcode "trim_view" at:
=> Toolset => Frontend-Content tab => Third-party shortcode arguments section.

Then I've called the above shortcode with the [wpv-conditional] display as given under:

[wpv-conditional if="( '[trim_view name='temp-distanza']' ne '' )"] 
 NOT EMPTY VIEW [trim_view name='temp-distanza']
[/wpv-conditional] 

[wpv-conditional if="( '[trim_view name='temp-distanza']' eq '' )" ] 
 EMPTY VIEW [trim_view name='temp-distanza']
[/wpv-conditional]

I can see now both condition works: hidden link

I've also adjusted the conditional display with the conditional block as well.

#2576251

My issue is resolved now. Thank you!