Skip Navigation

[Resolved] Option to change the number of results per page

This support ticket is created 4 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
- 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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by jozsefG 3 years, 12 months ago.

Assisted by: Waqar.

Author
Posts
#1825611

Hello Waqar. I'd need your help again. I have to implement a functionality to the job announcements grid I'm working on where the user can select how many items to be shown. Like Show 10 | 20 | 50 items.

hidden link

I managed it partially.

#1825629
#1828115

Hi,

Sorry about the delay in getting back on this.

I had an unusually busy forum queue, but I'll be able to share my findings on this, by the end of the day today.

Thank you for your patience.

regards,
Waqar

#1830355

Hi,

Thank you for waiting.

During testing on my website, I was able to make this "items per page" selector work, using the following steps:

1. In the view's "Search and Pagination" section, I used the updated HTML for the items per page selection links:


<span><strong>Arată:</strong> <a href="#" data-attribute="5" class="item-per-page-link">5</a> | <a href="#" data-attribute="10" class="item-per-page-link">10</a> | <a href="#" data-attribute="50" class="item-per-page-link">50</a> rezultate.</span>

2. In the "JS editor" below this section, I included this script, which updates the page, to include the selected items per post value in the URL parameter:


jQuery( document ).on( 'js_event_wpv_pagination_completed js_event_wpv_parametric_search_form_updated js_event_wpv_parametric_search_results_updated ready', function( event, data ) {

jQuery("a.item-per-page-link").click(function(event){
  event.preventDefault();
  var pageURL = jQuery(location).attr("href");
  var linkVal = jQuery(this).attr("data-attribute");
  
  var url = new URL(pageURL);
  url.searchParams.set("item-per-page", linkVal);
  
  var newUrl = url.href;
  window.location = newUrl;
});
  
});

3. The updated code for the "wpv_filter_query" hooked function, would look like this:


add_filter( 'wpv_filter_query', 'filter_items_per_page_custom_fn', 1000 , 3 );
function filter_items_per_page_custom_fn( $query_args, $view_settings ) {

	if ( ( !is_admin() && isset($view_settings['view_id'] ) ) && ( $view_settings['view_id'] == 1234 ) ) 
	{
		if(!empty($_GET['item-per-page'])) {
			$query_args['posts_per_page'] = $_GET['item-per-page'];
		}

	}

	return $query_args;
}

Please replace "1234" with the actual ID of the view.

Important Note: for this "items per page" selection to work effectively, it is important that the "Full page refresh when visitors click on the search button" option is selected in the "Custom Search Settings" section.

As for the issue with the "Use my location" button's icon, I was able to reprduce this on my website too and it has been reported to the concerned team already.

I'll keep you updated on this through this ticket and for now, you can use some custom script to override the text used for the button, for example:


jQuery( document ).on( 'js_event_wpv_pagination_completed js_event_wpv_parametric_search_form_updated js_event_wpv_parametric_search_results_updated ready', function( event, data ) {
    jQuery('.js-toolset-maps-distance-current-location').val("Use my location");
});

regards,
Waqar

#1836711

Hi Waqar, sorry for the late response.

The solution for the button icon problem works perfectly.

But the solution for changing the number of results in not working. It stays the same, shows all results. Could you check yourself too please? I get no error for this, not even in the console.

#1839795

Thanks for the update.

During troubleshooting, I noticed that "1234" and not the actual ID "493" of the view "Jobs" is used in the code snippet.
( screenshot: hidden link )

Please replace it with the actual view's ID and then test the items per page link again.

#1839803

Nooooo.... I can't believe I forgot that... :-S
Sorry Waqar, It's working now perfectly.
Thank you very much!!!!

#1839805

My issue is resolved now. Thank you very much Waqar! As usually you helped me out and I'm very grateful.