Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------------------------------------------*/
- /* The following displays posts by '_by_boat_price' & orders by this key
- /*-----------------------------------------------------------------------------------*/
- function bay_change_boat_archive_query( $query ) {
- if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'boat' ) ) {
- $query->set( 'meta_key', '_by_boat_price' );
- $query->set( 'orderby', 'meta_value_num' );
- $query->set( 'order', 'DESC' );
- }
- }
- add_action( 'pre_get_posts', 'bay_change_boat_archive_query' );
- /*-----------------------------------------------------------------------------------*/
- /* The following displays posts by '_by_boat_price' & orders by this key same as above
- /*-----------------------------------------------------------------------------------*/
- function bay_change_boat_archive_query( $query ) {
- if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'boat' ) ) {
- $query->set( 'meta_key', '_by_boat_price' );
- $query->set( 'orderby', 'meta_value_num' );
- $query->set( 'order', 'DESC' );
- $query->set( 'meta_query', array(
- 'relation' => 'OR',
- array(
- 'meta_key' => '_by_boat_price',
- 'compare' => 'EXISTS',
- 'type' => 'numeric'
- ),
- array(
- 'meta_key' => '_by_boat_enquire_pricing',
- //'value' => time(),
- 'compare' => 'EXISTS',
- )
- ));
- }
- }
- add_action( 'pre_get_posts', 'bay_change_boat_archive_query' );
- /*--------------------------------------------------------------------------------------------------------------*/
- /* The following displays posts by '_by_boat_price' & '_by_boat_enquire_pricing' but without the desired orderby
- /*-------------------------------------------------------------------------------------------------------------*/
- function bay_change_boat_archive_query( $query ) {
- if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'boat' ) ) {
- $query->set( 'orderby', 'meta_value_num' );
- $query->set( 'order', 'DESC' );
- $query->set( 'meta_query', array(
- 'relation' => 'OR',
- array(
- 'meta_key' => '_by_boat_price',
- 'compare' => 'EXISTS',
- 'type' => 'numeric'
- ),
- array(
- 'meta_key' => '_by_boat_enquire_pricing',
- //'value' => time(),
- 'compare' => 'EXISTS',
- )
- ));
- }
- }
- add_action( 'pre_get_posts', 'bay_change_boat_archive_query' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement