Skip Navigation

[Resolved] Show all (or more than 39) entries on map

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

Problem:

Specific WordPress Archive page pagination limitation with custom codes.

Solution:

See the example codes here:

https://toolset.com/forums/topic/show-all-or-more-than-39-entries-on-map/#post-2285363

Relevant Documentation:

This support ticket is created 2 years, 11 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 19 replies, has 4 voices.

Last updated by graemeH-3 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2273855

Tell us what you are trying to do?

Trying to display more than just the first page of paginated custom post results on the map on my archive page which I am designing a Template for.

Is there any documentation that you are following?

I found this one similar thread which makes it sound like the only way to do this is using 2 views, the user posted that they resolved their issue; I would be curious to know the solution, if it was two views.

https://toolset.com/forums/topic/show-all-entries-on-map-and-in-filter/

Alternatively, it would be nice to be able to display more than the maximum number of 39 results per page; without the only alternative being to display ALL posts.

I'm using this for a directory with over 500 locations, so I would like to show the user that there are many locations on the map when they arrive on page, while not overwhelming load times for the page.

Perhaps there is a way to choose to display 75 or 100 results per page; showing more locations on the map but limiting the length of an impossibly long list haha.

I also note that, when you zoom in on the map, it does not update or refresh the map to show the 39 allowable "within the window" of where the map is looking/zoomed in upon.

So for example if someone wants to zoom in on their state or area, while there may be more locations there than is initially shown on the map, it won't fill in to show those locations that didn't get included in the first page of 39 results.

Thanks so much for the help, been grinding out getting my directory up and minus the typical non-developer styling issues we all have designing pages I've been enjoying the plugin 🙂

#2274043

Nigel
Supporter

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

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

Hi there

If you want to display a different number of markers than the list of paginated posts then, yes, you will need two separate queries, one to generate the map markers and another to generate the paginated list of results.

When querying the database for a "page" of paginated posts the database only returns the posts belonging to that "page". It doesn't return all the posts and then somehow not use the posts that don't belong on the page. So the code that requested and received the list of paginated posts doesn't know about the other posts (although it will know how many potential posts there are, so it can say "showing posts 30-39 of 200" for example).

So the calling code has no way to display the other 190 posts.

You need to make a separate query to retrieve all of the posts if you want to display all of the posts as markers.

In the context of Toolset, that means adding 2 Views blocks to the page, one of which outputs a paginated list of results, and the second of which doesn't output anything but is simply used as the source for markers in a Map block.

If the objective is to reduce page load times this may not help much, inasmuch as you are running two queries not one. But the queries account for only a fraction of the rendering time, so it is still worth trying the page with two Views to see what the real-world results look like.

#2274487

If like you say the queries account for very little of the rendering time it's definitely worth a shot.

I understand I can add a second view block, and then I will need to put them within a conditional block to somehow display the filtered search results after someone does a search?

Is there any way to make these maps update to show more locations once a user has zoomed in on a particular area?

Thanks again for the help, looking forward to becoming a pro at this haha

#2274919

Hi,

Thanks for writing back.

> Is there any way to make these maps update to show more locations once a user has zoomed in on a particular area?
- No, I'm afraid, this is not supported. As Nigel explained, the map markers are dependent on the results that are coming from the view's query. Those results only change/update when the pagination or search filters are used and are not linked with the map's zoom status.

The structure of the page with two views and map will look like this:

1. First, you'll have a conditional block, that will show when the page loads and no search or pagination controls have been used.

The conditional statement for this block in the advanced editor will be:


  ( empty( '[wpv-search-term  param=wpv_post_search]') AND empty( '[wpv-search-term  param=wpv_paged]') ) 

Within this conditional block, you'll have the view that shows all results without pagination and the map block that shows all those results on the map.

2. Next, you'll have another conditional block, that will show when the search or pagination controls have been used.

The conditional statement for this block in the advanced editor will be:


 NOT ( empty( '[wpv-search-term param=wpv_post_search]') AND empty( '[wpv-search-term param=wpv_paged]') ) 

Within this conditional block, you'll have the map block that will be linked to the main view block that shows the paginated results.

3. After, the two conditional blocks, you'll have the main view that shows the limited results based on the pagination and the search filter.

As a result, when the page will load, a map with all the results will show, but the main view below it will only show the paginated results.

As soon as the visitor will use pagination or search, the map with all the results won't load, and only the map with the current page's results will start showing.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2275725

When I try to put the View within the conditional block it tells me that "Nested views creation is not supported at the moment."

However, to do this method, will the View of all locations be required to show the entire list of entries?

I'm not sure where I'm going wrong implementing your directions, however when I try this (even with the red box error saying "Nested views creation is not supported at the moment."), what I get is a map with all locations, and the accompanying list of all locations making the page load slowly because of their associated images and hundreds of location posts being loaded.

If it is necessary to have it load all location posts to display the map with all locations... Then this seems to entirely defeat the purpose because I could just have my regular view display all posts.

I suppose this entire effort is intended to
a) show all locations on the map for a users first arrival on page
b) not slow the page load speed down dramatically by loading hundreds of location posts

Right now I'm not seeing how the current solution achieves point b)

Am I missing something?

Thanks again

#2275757

The only other solution I can think of here would be if we can make the map load first, and lazy load all the archive posts below..

Any advice on how to do this?

I see searching support forums this was a requested feature back 7 years ago in 2015, but I'm not seeing any updated support topics where it's become available and I can't see any way to do so myself.

I'm hesitant to start messing with lazy load plugins, as I already use WP Rocket (I don't see any options there), and I was having big formatting problems with all features of WP Rocket enabled, eventually I had to disable a bunch of the javascript options and now the archive pages display correctly.

Thanks again

#2277013

Assuming that my reply 2 messages ago, #2275725 is correct, then it seems what I should really be focused on is how to speed up page load times for this particular archive page while simply turning off pagination and showing all results on the map.

I find many people asking and having the same issue.

https://toolset.com/forums/topic/help-with-ideas-for-how-to-reduce-page-load-time-maybe-using-lazy-load-option/
https://toolset.com/forums/topic/ajax-load-more-for-directory-listings/

The hosting I'm using has a CDN implemented, I'm using WP Rocket to minimize css, js etc, with lazy loading for all images on the website, and I have my images optimized by Short Pixel (each image which is loading per post in my archive is only a few kb each)...

I found in other support posts that conditional statements can slow your page load times down, I'm not using any conditional statements at all on my archive page..

I'm struggling to think of what else I can improve upon, but the load time for this archive page is insane, it will definitely result in a high bounce rate.

Can someone look at my page and tell me if I'm missing anything or what I can improve on ?

How can I share the page details in private somewhere.

Please help, so much work went in to the making of this directory; if it's so slow people just immediately leave the page then it's all going to go to waste.

Thanks,
G

#2277185

Thanks for writing back.

> I suppose this entire effort is intended to
> a) show all locations on the map for a users first arrival on page
> b) not slow the page load speed down dramatically by loading hundreds of location posts
> Right now I'm not seeing how the current solution achieves point b)

- Your observation is correct and based on what Nigel and I have explained in the previous replies, these two points counter each other.

The way map marker plotting works, to show the markers of all posts/results (point a), you'll need a query/view that fetches all the posts/results, which quite understandably, you'd like to avoid (point b). So, in short, the workarounds that we've been sharing will work to achieve something similar to what you have in mind. But, if the website's data is expected to grow to hundreds or thousands of posts and managing page loading times is also crucial, then it would probably be best to keep things simple. Finding the right balance between functionality and performance is the key.

The message about the nesting of views is showing because, you're most probably trying to add a post view within an archive, which is not supported. The steps that I shared in my last reply were for working on a regular page (as Nigel mentioned) and not in an archive.

Based on what is already shared in this thread, here is how I would proceed:

1. I would set the archive page to show the results with infinite scrolling and without any map. When the page will load, only the first page's results will be queried and as the visitor will scroll down, the results for more pages will keep getting added, which should improve the page loading time.

You'll find the settings for the infinite scrolling, in the archive's "Pagination" settings.
( screenshot: hidden link )

2. For showing results on a map, you can create a new page and then try to set it up, as suggested in my previous reply.

In case, you face any difficulty in setting it up, you're welcome to share temporary admin login details, along with the link to that page, in reply to this message.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

#2278133

Hey Waqar,

thanks for the advice.

Like you said, "Finding the right balance between functionality and performance is the key."

"The message about the nesting of views is showing because, you're most probably trying to add a post view within an archive, which is not supported. "

That's correct, I'm doing this on an archive page.

Through my extensive reading of support forums and all over the Toolset website before implementation, I read somewhere that having the Views plugin installed can slow things down.

For my purposes, it's sufficient to only display things on the archive page, so I opted to go this route, and don't have the Views plugin even installed as I don't think it necessary.

Even now I could create more pages if I like based on the different taxonomies I created and just create archive pages for each.

For user experience, I think a page without a map is pretty darn dull...

When I set out to create a directory, I certainly didn't intend for it to end up without even a map haha.

Could something like ,

https://toolset.com/forums/topic/speeding-up-map-load-time-map-with-550-pins/
the last reply, Reply 1515627

Help with my load times if I inserted this java script?

Or maybe some way to custom code for the map pins and posts to lazy load, while at least the search form and map frame itself load right away?

With this solution,

"2. For showing results on a map, you can create a new page and then try to set it up, as suggested in my previous reply."

Again, so, in this circumstance I would have 2 maps, the only benefit is like the top few posts I would have with some conditional statements would load a little faster? But then the map with all locations would be slow anyways, I would have to disable showing all the posts that populate the map that shows all locations?

I think to try not and defeat the purpose of the directory I created.. I need to display all posts, no pagination, and try and come up with some kind of lazy loading or otherwise to improve it.

Any custom code you can suggest on how to help?

Maybe like from the support topic I linked to?

Thanks again!
G

#2278273

Hello,

Waqar is on vacation, I will take care of this thread.

Yes, it is possible to use lazyload feature in Map marker popup.

You need to Enqueue lazyload JS file into your website, see my answer in that thread:
https://toolset.com/forums/topic/speeding-up-map-load-time-map-with-550-pins/#post-1508151

Since it is a custom codes problem, if you need more assistance for it, please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URLs, I can setup a demo for you

#2278801

Hi Luo,

thanks for the help, I see the code from your other support ticket and it looks promising for my purpose.

For the lazy load in the map marker, I did not mean with the map marker "pop up"; I just meant the map markers themselves.

But I guess, the map markers show up when the posts show up on the archive page.

I don't have images in my map marker pop ups which I need lazy loading for like in this example,
https://toolset.com/forums/topic/speeding-up-map-load-time-map-with-550-pins/#post-1508151

Would this code help at all if I am not using images in my map marker pop ups?
(I'm not sure if I need to install a plugin to go with these custom codes either)

I think maybe the code you provided here could help me,
https://toolset.com/forums/topic/speeding-up-map-load-time-map-with-550-pins/#post-1515627

I think I can copy paste that code with no modifications to help?

One more question is, is it possible to choose a posts per page for pagination as a custom number instead of maximum 39? Maybe I could set it to 200, instead of trying to load all 600 custom posts in the archive at once..

Thanks again for your help and expertise!
G

#2279621

No, those custom codes helps only for images in marker popup, it won't help for lots of map markers.
Toolset Blocks and Toolset Maps plugin both support cache feature, as you can see in that old thread, that client was displaying 550 markers in the same map.

Yes, it is possible to setup the pagination limitation, you can follow our document to setup a Toolset WordPress Archive, and change the pagination settings:
https://toolset.com/course-lesson/creating-a-custom-archive-page/#add-pagination-to-the-archive
section "Add pagination to the archive"

#2283139

Luo,

I'm asking if I can increase the pagination option past the maximum 39 posts per page.

Of course I have found where to make pagination adjustments; that's how I know there is a maximum limit on how many posts can be shown.

I followed your link,
https://toolset.com/course-lesson/creating-a-custom-archive-page/#add-pagination-to-the-archive

This tells me nothing about customizing the number of posts to be shown per page.

Is there a way to increase the maximum number of posts to be shown on the page past 39?

Can I find this somewhere in the custom code and adjust it up to 200?

Thanks

#2283143

Is there a way you can put me in touch with Toolset user, aaronS-5?

Maybe could you please email him my contact details and ask him to send me an email?

It seems he was having nearly all of the same problems I have had; maybe he found some solutions on his own because most the threads don't seem to be resolved to the goals he and I both have.

Otherwise, are you aware about any Toolset Contractor Developers that specialize specifically on creating custom map and archive pages?

Thank you

#2285363

I assume you are going to add a pagination limitation dropdown into the search form, and change the "posts_per_page" parameter of WordPress Archive page.

Unfortunately, there isn't such kind of built-in feature within Toolset plugins, as a workaround, you can consider custom codes, for example:

add_shortcode('my-pagination-dropdown', function($atts, $content){
	$arr = array(1, 2, 4); // here replace the option values
	$name = 'my-pagination';
	$options = '';
	$url_param = '';
	if(isset($_GET[$name])){
		$url_param = $_GET[$name];
	}
	foreach($arr as $key => $value){
		$selected = '';
		if($value == $url_param){
			$selected = 'selected';
		}
		$option .= sprintf('<option value="%1$s" %2$s>%3$s</option>', $value, $selected, $value);
	}
	$res = sprintf('<select name="%1$s" class="my-pagination-dropdown">%2$s</select>', $name, $option);
	return $res;
});

add_action('pre_get_posts', function($query){
	if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'test-cpt-1' ) ) { // replace 'test-cpt-1' with your custom post type slug
		$name = 'my-pagination';
		if(isset($_GET[$name])){
			$query->set( 'posts_per_page', $_GET[$name] );
		}
	}
},99);

Use below shortcode to output a dropdown field in the custom search form:
[my-pagination-dropdown]

More help:
https://developer.wordpress.org/reference/hooks/pre_get_posts/
https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters