Hi, I've built a Product View that works just like the archive page (same filters, same pagination...). I would like to activate the "per-page" buttons just like on the archive page, but I found the custom code doesn't work here.
I tried to add a condition on func_include_child_terms:
add_filter('pre_get_posts','func_include_child_terms',999);
function func_include_child_terms( $query ) {
if ( ( $query->is_main_query() && $query->is_tax( 'product_cat' ) ) || ( $query->is_main_query() && is_page(14053) ) ) {
but it doesn't work. Can you help me again?
Hey Jamal, I could create the script by myself.
This is what I set up:
/* func_view_posts_per_page */
add_filter( 'wpv_filter_query', 'func_view_posts_per_page', 99, 3 );
function func_view_posts_per_page( $query_args, $view_settings, $view_id ) {
$views = array( 14054 );
if ( in_array( $view_id, $views ) ) {
$pager = my_pager_func();
if ( $pager > 0 ) {
$query_args['posts_per_page'] = $pager;
}
}
return $query_args;
}
It works fine. I've also found an issue on the JS code.
ajax_reload_with_pager function was triggering a specific Brand checkbox ('#pa_brand-airav), but it doesn't exist on all the archive pages and on the search page:
function ajax_reload_with_pager(){
jQuery('.per-page a').off('click').on('click', function(event){
event.preventDefault();
var link = jQuery(this);
var nposts = link.data('pager');
var pager = jQuery('input[name="pager"]');
pager.val(nposts);
jQuery('#pa_brand-airav').trigger('change');
})
}
My solution is to add an hidden submit button and click it to trigger ajax_reload_with_pager:
[wpv-filter-submit class="btn-submit" style="display:none"]
jQuery('.btn-submit').trigger('click');
My issue is resolved now. Thank you!
Awesome! I wanted to start working on it when I realized that the ticket was resolved.
I am glad, you could fix it.