Advertisement
Guest User

Untitled

a guest
Mar 26th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /*-----------------------------------------------------------------------------------*/
  2. /* The following displays posts by '_by_boat_price' & orders by this key
  3. /*-----------------------------------------------------------------------------------*/
  4.  
  5. function bay_change_boat_archive_query( $query ) {
  6. if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'boat' ) ) {
  7. $query->set( 'meta_key', '_by_boat_price' );
  8. $query->set( 'orderby', 'meta_value_num' );
  9. $query->set( 'order', 'DESC' );
  10. }
  11. }
  12. add_action( 'pre_get_posts', 'bay_change_boat_archive_query' );
  13.  
  14. /*-----------------------------------------------------------------------------------*/
  15. /* The following displays posts by '_by_boat_price' & orders by this key same as above
  16. /*-----------------------------------------------------------------------------------*/
  17.  
  18. function bay_change_boat_archive_query( $query ) {
  19. if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'boat' ) ) {
  20. $query->set( 'meta_key', '_by_boat_price' );
  21. $query->set( 'orderby', 'meta_value_num' );
  22. $query->set( 'order', 'DESC' );
  23. $query->set( 'meta_query', array(
  24. 'relation' => 'OR',
  25. array(
  26. 'meta_key' => '_by_boat_price',
  27. 'compare' => 'EXISTS',
  28. 'type' => 'numeric'
  29. ),
  30. array(
  31. 'meta_key' => '_by_boat_enquire_pricing',
  32. //'value' => time(),
  33. 'compare' => 'EXISTS',
  34. )
  35. ));
  36. }
  37. }
  38. add_action( 'pre_get_posts', 'bay_change_boat_archive_query' );
  39.  
  40. /*--------------------------------------------------------------------------------------------------------------*/
  41. /* The following displays posts by '_by_boat_price' & '_by_boat_enquire_pricing' but without the desired orderby
  42. /*-------------------------------------------------------------------------------------------------------------*/
  43.  
  44. function bay_change_boat_archive_query( $query ) {
  45. if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'boat' ) ) {
  46. $query->set( 'orderby', 'meta_value_num' );
  47. $query->set( 'order', 'DESC' );
  48. $query->set( 'meta_query', array(
  49. 'relation' => 'OR',
  50. array(
  51. 'meta_key' => '_by_boat_price',
  52. 'compare' => 'EXISTS',
  53. 'type' => 'numeric'
  54. ),
  55. array(
  56. 'meta_key' => '_by_boat_enquire_pricing',
  57. //'value' => time(),
  58. 'compare' => 'EXISTS',
  59. )
  60. ));
  61. }
  62. }
  63. add_action( 'pre_get_posts', 'bay_change_boat_archive_query' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement