Hi, I wanto to display a slideshow of Woocommerce featured products. I've built a View with AJAX pagination where I display 4 items per page.
I've added this hook to get the Woocommerce featured products:
add_filter( 'wpv_filter_query', 'featured_products',99,3 );
function featured_products( $query_args,$views_settings, $view_id) {
if ($view_id == 4304){
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'product',
'posts_per_page' => 4 ,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
}
return $query_args;
}
The View works fine, but not the AJAX pagination.
How can I fix it?
thanks
Umberto
Hi Umberto,
I am not sure if the pagination of Views will work with the pagination you have in the WordPress query in the hook.
What if you avoid having paged content in the WP Query and keep the agitation in the view. What happens then?
Hi, if I remove the pagination from the hook, the view pagination still doesn't work. Actually, I've added it to the hook just to try it, but I first used the code without it.
Now I've tested with this code:
/* Featured products based on WooCommerce featured star */
add_filter( 'wpv_filter_query', 'featured_products',99,3 );
function featured_products( $query_args,$views_settings, $view_id) {
if ($view_id == 4304){
$query_args = array(
'post_type' => 'product'
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
}
return $query_args;
}
Same result. When I click on the pager arrow, it reload the same entries.
cheers
Hi Umberto,
Would you please get back to us with the URL/USER/PASS of your website after you copy the website to the staging version? So we can test things out without the fear of affecting a live website.
Also tell us the information below:
- Which view or page or content template you use
- The URL that it is used in.
- Where to see the code that you used.
Thanks.
Hi there,
Thank you for the information. I went to the view in question and used the Query filter button there to add the filter.
I selected the Product Visibility taxonomy and in the filter value selected features.
I kept the rest of the pagination the same and I deactivated your custom code from Toolset Settings.
The result seems to be correct now. It has 5 featured items and as the pagination is set to 4 it shows 4 items and loads the other one later.
Thanks.
Wow! That's so easy and cool!
There is no documentation about this. I discovered that Featured products are defined by Product Visibility taxonomy because I found the custom code on Toolset support. I didn't check for it in the view because I thought it was a "not accessible" WooCommerce's private taxonomy. I found the custom code solution in many support threats, so it seems it is the only solution.
thank you