Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Custom shortcode to display active auctions (without future and past ones), usage [number_of_active_auctions]
- Code should be copy pasted to your child theme functions.php file.
- */
- add_shortcode('number_of_active_auctions', 'number_of_active_auctions_function');
- function number_of_active_auctions_function( ) {
- global $woocommerce;
- $meta_query = $woocommerce->query->get_meta_query();
- $args = array(
- 'post_type' => 'product',
- 'post_status' => 'publish',
- 'ignore_sticky_posts' => 1,
- 'meta_query' => array(
- 'relation' => 'AND',
- // don't include past auctions
- 'past_auctions' => array(
- 'meta_key' => '_auction_closed',
- 'meta_compare' => 'NOT EXISTS'),
- // don't include future auctions
- 'future_auctions' => array(
- 'meta_key' => '_auction_started',
- 'meta_compare' => 'EXISTS')
- ),
- 'tax_query' => array(array('taxonomy' => 'product_type' , 'field' => 'slug', 'terms' => 'auction'))
- );
- $products = new WP_Query( $args );
- echo "Number of active auctions: ".$products->found_posts;
- wp_reset_postdata();
- }
Advertisement
Add Comment
Please, Sign In to add comment