Sauter la navigation

[Résolu] How to display the featured products only with views

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to display the featured products only with views

Solution:
You shoud try to use the view's filter hook "wpv_filter_qeury" to filter only feature products and display it.

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/views-pagination-not-working-when-the-query-is-done-by-js/#post-1225687

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

This support ticket is created Il y a 5 années et 9 mois. 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)

Marqué : 

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par Pat Il y a 5 années et 9 mois.

Assisté par: Minesh.

Auteur
Publications
#1225591

Pat

Hello,

I'm using a Views in order to display featured products. The aim is to display this as a slider with 4 products per page and an ajax pagination with prev / next.

As there is no field available for featured inside the Views filter, I have created a function :

add_filter( 'wpv_filter_query', 'featured_products',99,3 );
function featured_products( $query_args,$views_settings, $view_id) {
     
if ($view_id == 1331){
$query_args = array(
  'post_type'  => 'product',
  'tax_query' => array(
    array(
      'taxonomy'     => 'product_visibility',
      'field'   => 'name',
      'terms' => 'featured',
      'operator' => 'IN'
    ),
  ),
);
}
    return $query_args;
}

This code is fine but the issue is that this function takes control of all pagination parameters. That means that even if I have defined a slider with 4 items per page, all featured products are displayed.

How can I use the Views parameters in the same time than the specific query made by the function?

Regards
Pat

#1225687

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I've used the following code on my test site to display on the featured products with slider view and it just works fine.

Can you please try to use the following code:

add_filter( 'wpv_filter_query', 'func_featured_products',99,3 );
function func_featured_products( $query_args,$views_settings, $view_id) {
      
if ($view_id == 1331){
$query_args['tax_query'] = array(
    array(
      'taxonomy'     => 'product_visibility',
      'field'   => 'name',
      'terms' => 'featured',
      'operator' => 'IN'
    ),
  );
}
    return $query_args;
}

If the above code does not help, please run a compatibility test:
Could you please try to resolve your issue by deactivating all third-party plugins as well as the default theme to check for any possible conflicts with any of the plugins or themes?

#1225695

Pat

Hi Minesh,

Perfect ... as usual !
Regards
Pat