Skip Navigation

[Resolved] Pagination should not filter view items

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

Problem:
How to pre-filter the view's results with taxonomy term before view display

Solution:
You can use view's hook wpv_filter_query to modify view's query on fly and it will allow you to add taxonomy term to prefilter the view's output.

you can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/pagination-should-not-filter-view-items/#post-616712

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 6 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
- 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 12 replies, has 2 voices.

Last updated by gerhardS 6 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#616584

I would like to be able to show all my posts on the map, but not all at once in the post list below the map. In the list only one page at the time should be displayed and I would like to browse the list page per page using pagination controls. This should not influence the map display.

I am trying to:

show all posts of a certain category on a map, but only 2 per page at a time.

Link to a page where the issue can be seen:

hidden link

I expected to see:

all 3 posts on the map, but only 2 per page in the list below it.

Instead, I got:

only those posts on the map, that are displayed on the current page.

#616620

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - correct way to do that is to have two separate view's one view to display map and one view to display the posts with pagination respectively.

#616632

Thank you for the fast response.

I do not want the pagination to change the map display, but want any filter I have on the map to restrict, what is shown in the pagination view.

Can I do this by nesting the views? I tried it, but it does not work. I do not want to put the child view (with paginated posts) in the loop, because it should be displayed only once. But the child should take over the taxonomy filter from the parent (with the map and some filters.

#616669

I might have found a solution, but I would need to display the view with a certain URL-Parameter. Is it possible to set an URL Parameter (search term) before a view is displayed?

I have the filter

[wpv-control-post-taxonomy taxonomy="category" type="select" format="%%NAME%%" url_param="wpv-category"]

but as it is not possible to set a default value, I would like to get wpv-category into the page url before the view is displayed. Of course the best solution would be to be able to set a default value, using for example an attribute of the view shortcode.

#616712

Minesh
Supporter

Languages: English (English )

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

As I understand - you want to prefilter the view's result before it get displayed with taxonomy term - correct? If yes:

You can use view's hook wpv_filter_query to modify view's query on fly and it will allow you to add taxonomy term to prefilter the view's output.

For example - you should add following code to your current theme's functions.php file:

add_filter('wpv_filter_query', 'wpv_show_prefilter_data', 99, 3);
function wpv_show_prefilter_data ( $query_args, $view_settings, $view_id ) {
   
     if( $view_id == 9999) {
      
If(count($_GET) == 0) {   
        $query_args['tax_query'][] = array(
            array(
                'taxonomy' => 'category',
                'field'           => 'slug',
                'terms'        => 'customer-focus'
            )
        );
   }       
          
    }
    return $query_args;
}

Where:
- Replace 9999 with your original View ID
- Adjust your taxonomy slug and terms slugs

More info:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#616737

Thank you very much for the suggestion, but this can only be the very last thing to try. I do not want to hardcode this information somewhere in functions.php for possibly many views and I need the URL parameter anyway to be able to use the same query in the child view (pagination).

I will try to write some JS code in the view itself to change the URL or find some other way to manipulate the URL.

It would be very much appreciated, if you would integrate the possibility to set a default value to the dropdown list. I saw that there have been other users needing this and it is an option anybody would expect to have (at first I hoped, as others have, that the default label would do it).

Also if I use a parameter of the view shortcode to initialize the query instead of the URL parameter, the selection control does not work at all (whatever I select has no effect).

#617299

Minesh
Supporter

Languages: English (English )

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

Well - even you can set the passed arguments from view's shortcode attribute and later use it withing wpv_filter_query hook and also you can catch the view's shortcode attribute values using shortcode [wpv-attribute] and later assign the passed shortcode argument to your child view as well.

More info:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#vf-309292

#617354

I tried to use wpv-attribute already, as it would be the best solution. But if I use the filter with wpv-attribute and the user selects any category in the control on the frontend, nothing happens. The control seems only to be functional with the URL filter.

Also, even if it would work, how could I pass the selection of the user to the child view with the pagination?

#617558

Minesh
Supporter

Languages: English (English )

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

But if I use the filter with wpv-attribute and the user selects any category in the control on the frontend, nothing happens. The control seems only to be functional with the URL filter.
==> Well - I do not know your view's setting yet, is it possible for you to send me temporary access details with problem URL?

Also, what is your required output with a test case example, I'm happy to help you further once I got these required details.

how could I pass the selection of the user to the child view with the pagination?
===>.
Also - if you want to catch the URL param you can catch the URL param value using the shortcode: [wpv-search-term]

For example:

[wpv-search-term param="url-param-name"]

Where:
- Replace "url-param-name" with your actual URL param name.

More info:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#617879

Minesh
Supporter

Languages: English (English )

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

Ok - as you said everything is working, the only issue remains here is to prefilter the view's results with

category="places"

What If I write dynamic script for you that will catch the shortcode attribute "category" and apply it dynamically before the view loads using view's hook wpv_filter_query?

That means - if you place view at page 1 with category="places" and on page 2 with category="xyz" it will catch the shortcode attribute "category" value dynamically.

If yes - I need FTP access details of your install.

#618048

I do not have the possibility to create a temporary FTP user and I could put the code into functions.php myself.

But there seems to be still a misunderstanding . If I use the shortcode attribute "category", the control with the dropdown list of categories will not work. If the user selects anything, the filter is not updated (nothing at all happens). This only works, if I use the option to use the URL parameter in the control, as it is currently set. You can edit the category filter control to use the shortcode attribute and try to change the category in the dropdown: It will not do, what it should.

Why is it not possible to set a default category in the category filter control, which then would set the necessary URL parameter?

I can try to use this hook and see if this sets the URL parameter. Could you please provide the code using the shortcode attríbute instead of hardcoding anything? Then I could put it into functions.php myself. But will it set the required URL parameter?

#618345

Minesh
Supporter

Languages: English (English )

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

Well - It will be great if you can setup FTP access details for me as soon as possible.

And login to FTP and delete the following code from your functions.php file.

add_filter('wpv_filter_query', 'shortcode_attribute_func', 10, 2);
function shortcode_attribute_func($query, $setting) {
    if($setting['view_id'] == 1858){
        global $WP_Views;
        $attributes = $WP_Views->view_shortcode_attributes;
        print_r($query);
		print_r($setting);
		
    }
    return $query;

I need FTP access as I need to add shortcode attribute and filter to match your requirement so I need to do few tests.

#618443

Thank you very much for trying to help, but I really don't want to use a complicated PHP hack to solve this problem. And it seems to be rather complicated as even you could not solve the problem just by editing the functions.php and need ftp access apparently to change even more files.

I will use another solution, namely by putting in a simple Map in the page and a button to open another page with the filters. This way I can set any URL parameter I need to initialize the filters and make it work as it should.

Maybe one day, if more people need this functionality it will be integrated in the plugin with an easy user interface, which is why I am using your plugins instead of programming in PHP.