Guest User

Untitled

a guest
Jul 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. function woocommerce_pre_get_posts( $query ) {
  4.  
  5. if ( ! is_admin() && is_post_type_archive( 'product' ) && $query->is_main_query() ) {
  6.  
  7. // Option 1
  8. $args = array(
  9. array(
  10. 'meta_key' => '_price',
  11. 'value' => array( 50, 500 ),
  12. 'compare' => 'BETWEEN'
  13. )
  14. );
  15.  
  16. // Option 2
  17. $args = array(
  18. array(
  19. 'meta_key' => '_price',
  20. 'value' => array( 50, 500 ),
  21. 'compare' => 'BETWEEN',
  22. 'type' => 'NUMERIC'
  23. )
  24. );
  25.  
  26. // Option 3
  27. $args = array(
  28. 'relation' => 'AND',
  29. array(
  30. 'meta_key' => '_price',
  31. 'value' => 50,
  32. 'compare' => '>=',
  33. ),
  34. array(
  35. 'meta_key' => '_price',
  36. 'value' => 500,
  37. 'compare' => '<=',
  38. )
  39. );
  40.  
  41. $query->set( 'meta_query', $args );
  42. }
  43. }
  44. add_action( 'pre_get_posts', 'woocommerce_pre_get_posts', 20 );
Add Comment
Please, Sign In to add comment