Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get products from events category and sort by woodate.
- *
- * Alter the main loop
- *
- * @uses pre_get_posts hook
- */
- function theme_modify_the_main_query( $query ) {
- // Order by: woodate
- if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'woodate' ) {
- // Modify the main query
- if( ! is_admin() && $query->is_main_query() ) {
- // Get from Events category
- $tax_query = array(
- array(
- 'taxonomy' => 'product_cat',
- 'field' => 'slug',
- 'terms' => 'events' // Events category (term) slug
- )
- );
- $query->set( 'tax_query', $tax_query );
- $query->set( 'meta_key', 'woodate' );
- $query->set( 'orderby', 'meta_value_num' );
- $query->set( 'order', 'DESC' );
- }
- }
- }
- add_action( 'pre_get_posts', 'theme_modify_the_main_query' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement