Skip Navigation

[Resolved] Maps Plugin API Problem

This thread is resolved. Here is a description of the problem and solution.

Problem:
Using URL referrer restrictions for the API key is preventing Maps from working properly.

Solution:
This will be fixed in Maps 1.5, which will allow you to add separate API keys for client-based requests (with URL restrictions) and server-based requests (with optional IP address restrictions).

This support ticket is created 6 years, 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 24 replies, has 2 voices.

Last updated by Nigel 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#913419

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, we seem to have gone off track somehow trying different things.

Let me recap how it works on my site.

- I have a custom WordPress Archive for a taxonomy archive. The terms of that taxonomy have an address custom field (some of which have the field completed, others not).
- In the Loop Editor of this archive the wpv-loop section outputs a list of matching posts for the archive being displayed.
- Immediately after the wpv-layout-start shortcode I insert a View (which will display the address on a map, or, for testing, simply output the address as text)
- This View in the content selection queries my taxonomy terms. It includes a Query Filter "Taxonomy is set by the page where this View is inserted".
- In the Loop Output section I add the map shortcode immediately after the wpv-layout-start shortcode. I also for testing output the address field directly, and use it in a conditional shortcode, so that the whole Loop Output section looks like this:

[wpv-layout-start]
<p>Country marker field: [types termmeta='country-marker'][/types]</p>
[wpv-conditional if="( '[types termmeta='country-marker'][/types]' ne '' )"]
[wpv-map-render map_id="map-2"][/wpv-map-render]
[/wpv-conditional]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          [wpv-map-marker map_id="map-2" marker_id="marker-[wpv-taxonomy-id]" marker_termmeta="wpcf-country-marker"][/wpv-map-marker]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

On your site you are using Layouts, so the set-up would be almost the same, but you would use a WordPress Archive cell inside the Layout assigned to the taxonomy archive, instead of assigning a custom WordPress Archive directly to the taxonomy archive.

But when I look I see the Layout "Places Taxonomy Layout" which is assigned to the Places archive doesn't contain an archive, and instead contains a View: "Places taxonomy Archive Pages View".

This View doesn't link to a second View as in my example, and doesn't output the term fields or attempt to output a map or markers, so I'm missing something there.

In any case, with the back and forth of trying to get it working I think I have confused or misled you.

Could you please read what I have listed here as the correct way to set this up and try again? If you are not sure about any of the steps I listed, please ask.

#913486
Capture.JPG

Hi Nigel,

Thanks for your reply.

1- The reason I don't have an archive cell is that the views that are generated inside automatic archive cell does not have custom search options, and I need to give the visitors the ability to filter the posts using custom searches (like the real estate demo site).
I submitted a support ticket, but i was able to solve this issue by creating a view that shows the posts based on the term slug.
here is my ticket:
https://toolset.com/forums/topic/problems-in-creating-custom-taxonomy-archive-page/

however, this is a side issue. the maps were not working before i add this view.

2- I have a view that shows the maps (this is the one you helped me to fix, apart form the conditioal issue).
the view called:
Places Map View

the loop editor of this view has the following:

[wpv-layout-start]
<p>Test: [types termmeta='place-address'][/types]</p>
[wpv-conditional if="( '[types termmeta='place-address'][/types]' ne '' )"]
  [wpv-map-render map_id="map-2"][/wpv-map-render]
[/wpv-conditional]
    [wpv-items-found]
    <!-- wpv-loop-start -->
        <wpv-loop>
            [wpv-map-marker map_id="map-2" marker_id="marker-[wpv-taxonomy-id]" marker_termmeta="wpcf-place-address" id="[wpv-taxonomy-id]"][/wpv-map-marker]
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]

3- This view is inserted inside the layout as follows:

[yoast-breadcrumbs]
<div class="separator-2"></div>
[wpv-view name="places-map-view"]
[wpv-view name="places-children-taxonomy-view"]
<div class="separator-2"></div>
[wpv-view name="places-taxonomy-archive-pages-view" wpvplace="[wpv-post-slug id='$current_page']"]

the first view is the places map view, the other 2 views are irrelevant. one of them shows the children taxonomy terms, and the other one is the one i described in #1.

Therefore, I still don't understand what I am doing wrong. Please check the attached screenshot. I used Notepad++ to compare the code i have now, with the code you pasted in your last response.

the only difference i see is the name of the term meta field.
I have it as "Place Address" and you have it as "country marker"

so the logic in my website should be:
1- i fill the address
2- the map is generated in the view called Places Map view
3- the view is inserted in the layout.

this logic works without the conditional (So it will show the map for the places with address, and will show a generic map when there is no address

when I add the conditional code, step 2 get broken.

Can you kindly have another look please?

thanks.,

#913678

Hi Nigel,

I added addresses to multiple other places taxonomy, to widen the test.

here are the results..extremely weird behaviour.

Please note that i don't have caching mechanism active, and I cleared all saved addresses in the plugin, several times:

I added 2 new taxonomy terms today. I got the map showing correctly only on ONE new taxonomy I added today.

this is a perfect page:
hidden link

this is the second taxonomy term. it is showing: "No Items found", although the map renders correctly when I edit the term from the backend.

hidden link

-----

As for the existing terms, when i add the address, it dos not show the map, but it also does not show "No items found"..!!!!!!

here is the one we test, (by the way, i changed the address to an address in the USA, another address in Australia, same output. nothing shows up).

i even have the same address that showed in the working page, in Jericho, but it is not showing in Jericho page..!!!
extremely bizzare.

her is the address, i copied it from google maps, and it showed in the jericho page backend too!!!:

Nagaa Al Deir Al Abyad Al Bahri - Edfa, Awlad Azaz, Markaz Sohag, Sohag Governorate, Egypt

hidden link

here is another existing term that I added the address to, same performace as Jericho, doesn't show anything.

hidden link

by the way, both the "test" address text, and the actual map showed in the only working term page, but i removed the test part when i saw it working.

can you please check to see why i have 3 different output results, for the same code?

#913789

Hi nigel and the team.

i created a test post,
hidden link

assigned it to this place:
hidden link

then inserted the maps view into the post:

[wpv-view name="places-map-view"]

the maps showed perfectly on the post, while it didn't show on the term page,

so there is something wrong in the logic used in the term page.

thanks

#913850

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-06-15 at 09.41.37.png

I re-visited your site.

Your View places-map-view has the wrong Query Filter. It currently has the "Taxonomy is set by the current post" but it should be "Taxonomy is set by the page where this View is inserted" because we are inserting it on an archive.

I also unchecked the option "Don't show empty terms" which would exclude the term coming from the archive if it had no posts (i.e. the archive being viewed was empty).

I added a few lines of output to the View to identify if the shortcodes are outputting what is expected.

I found something that might account for why this isn't working, which I can't explain, but which I can fix.

This page works: hidden link

Inside the loop itself I output the taxonomy slug (as an H3). There is only one iteration of the loop, for the term white-monastery-sohag.

This page doesn't work: hidden link

In this case the loop iterates twice, both for jericho and for the parent term holy-land.

It is this which seems to prevent the types field for the term meta working correctly outside the loop where we want to use it in a conditional shortcode for the map.

I can't identify why that happens, despite looking.

To fix it you can edit the View and set a limit of 1, so that there is only one iteration of the loop, in which case the types shortcode before the loop will work.

You have warning notices from WPML about out-of-synch taxonomy translations, I recommend you follow the linked instructions to update those. It's possible that could be influencing this, and it might be a good idea to disable WPML for testing until you have everything working and then re-enable it.

I have been discussing this with my colleague and when time allows we want to dig deeper to try and understand why sometimes just the child term is passed, and sometimes both the parent and child terms are passed. I'm taking a copy of your site in case we need it for testing.

#914238

Hi Nigel,

Thanks for the detailed response.

I limited the number to 1. some maps worked, some didn't.. exremely unreliable results.

this is a new term: it shows "no items found":
hidden link

I know that the setup is complicated, but i wish that you guys find a solution.

thanks

#915307

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I think the problem here with the limit=1 solution is that we can't control the order according to the term hierarchy and so we might be cutting off the wrong term when two are passed.

I installed your site locally and spent some more time analysing this. I'm still not sure why two terms are sometimes being passed when they don't appear to be on my local test site, but in any case I drafted a solution using the wpv_filter_taxonomy_query hook to only pass the child term when on such pages.

This is the code you would need to add:

function tssupp_limit_tax_query( $tax_query_settings, $view_settings, $view_id ){

	$term_ids = $tax_query_settings['include'];

	if ( count( $term_ids ) > 1 ) {

		foreach ($term_ids as $key => $term_id) {

			$term_obj = get_term( $term_id, 'place' );

			if ( $term_obj->parent == 0 ) {
				unset( $term_ids[$key] );
			}
		}
	}

	$tax_query_settings['include'] = $term_ids;

	return $tax_query_settings;
}
add_filter( 'wpv_filter_taxonomy_query', 'tssupp_limit_tax_query', 101, 3 );

It worked in the testing I did on my local copy of your site, but please try the code on your own server and try some further tests and see if it holds up.

Fingers crossed.

#917704

Hi Nigel,

Thanks for the code.

I added it to the functions.php

if the term has parent, it works:
hidden link

however, if the term doesn't have a parent, it doesn't work:
hidden link

(I edited the place by adding a dummy parent, it worked, then removed the parent, it didn't work)

the implications of this is that the top place will not show maps. can you please help me in this last step?

thanks a lot for all your help.

#917728

Hi Nigel,
I also noticed that the slug shown in the view of Jericho is:
st-mary-abu-sefein-monastery-azab-fayyoum

hidden link

this is the slug of another place that is completely unrelated to Jericho. not a parent of child to Jericho at all:
hidden link

thanks!

#917959

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-06-26 at 15.06.12.png

I suspect I'm digging a deeper hole, so I started over from scratch on a local test site to try and get this working without producing any unexpected side effects.

The root cause of the issue is that when on a taxonomy archive page the current term isn't readily accessible. When we insert a View on an archive page and use a filter to set the term according to the page where the View is shown (i.e. the archive page) it passes all the hierarchical terms and not just the "current" term, e.g. the Barcelona location archive at location/spain/barcelona passes both barcelona and the parent spain. IMHO that's not right, and I will discuss with the developers.

But in the meantime, the solution requires knowing the current term on a taxonomy archive page.

So, please remove any custom code you have added previously, we will start over.

Add the following code, which declares a custom shortcode that can be used on a term archive page to output the current term (by default the term_id, but you can use the return attribute to produce the title or slug instead, not needed here).

add_shortcode( 'archive-term', function( $atts = [] ){

	$output = "";

	$atts = shortcode_atts( [
		'return' => 'term_id'
	], $atts );

	$return = $atts['return'];

	$obj = get_queried_object();

	if ( isset( $obj ) ) {
		$output = $obj->$return;
	}

	return $output;
});

Go to Toolset > Settings > Front-end content and register this shortcode to be used for Views attributes.

You'll need a custom WordPress Archive for the place taxonomy.

You can either edit one directly at Toolset > WordPress Archives, or if using Layouts assign a Layout to the taxonomy archive and insert an archive cell (a newly created or an existing one).

Include whatever fields you want in the Loop Output section (e.g. the post title at a minimum).

Outside of the Loop you need to insert a View which will be responsible for outputting the map and marker.

This can be within the custom archive itself, immediately after the wpv-layout-start shortcode, or in another cell in the same Layout assigned to the archive. But it cannot be a View cell, because we will need to supply a shortcode attribute, so you would need to insert the View in a Visual Editor cell with the wpv-view shortcode.

We are going to directly pass the term of the current archive to the View using the "terms" shortcode attribute, with the value generated by our custom shortcode, like so:

[wpv-view name="geo-tax-term-map" terms="[archive-term]"]

(Obviously you will edit the View slug.)

The View itself will be a taxonomy View not a posts View, that will query your place taxonomy.

Add a Query Filter Taxonomy term ID is set by the shortcode attribute "terms" (see screenshot).

Then your View output will look something like this (you'll again need to edit the field slugs etc.)

[wpv-layout-start]
[wpv-conditional if="( '[types termmeta='map-address'][/types]' ne '' ) AND ( '[types termmeta='map-address'][/types]' ne ' ' )"]
[wpv-map-render map_id="map-4"][/wpv-map-render]
[/wpv-conditional]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
			[wpv-map-marker map_id="map-4" marker_id="marker-[wpv-taxonomy-id]" marker_termmeta="wpcf-map-address"][/wpv-map-marker]          
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
	[/wpv-no-items-found]
[wpv-layout-end]

I tested this extensively with a site that has a variety of hierarchical location terms, some of which are assigned to posts, some not, some of which have address term fields, some not, and found that it works smoothly. (Note I found a quirk which meant we have to check that the address field is not empty and not a space character either, hence the longer conditional.)

Please try again, following the above steps, which I know to work.

If it doesn't work on your site I'll set up a demo on an online server where you can see it working on my test site and examine how it is built.