| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | function epl_shortcode_listing_auction_callback( $atts ) { |
| 35: | $property_types = epl_get_active_post_types(); |
| 36: | if ( ! empty( $property_types ) ) { |
| 37: | $property_types = array_keys( $property_types ); |
| 38: | } |
| 39: | |
| 40: | $attributes = shortcode_atts( |
| 41: | array( |
| 42: | 'post_type' => $property_types, |
| 43: | 'status' => array( 'current', 'sold', 'leased' ), |
| 44: | 'limit' => '10', |
| 45: | 'template' => false, |
| 46: | 'location' => '', |
| 47: | 'tools_top' => 'off', |
| 48: | 'tools_bottom' => 'off', |
| 49: | 'sortby' => '', |
| 50: | 'sort_order' => 'DESC', |
| 51: | 'query_object' => '', |
| 52: | 'pagination' => 'on', |
| 53: | 'instance_id' => '1', |
| 54: | 'class' => '', |
| 55: | ), |
| 56: | $atts |
| 57: | ); |
| 58: | |
| 59: | if ( is_string( $attributes['post_type'] ) && 'rental' === $attributes['post_type'] ) { |
| 60: | $meta_key_price = 'property_rent'; |
| 61: | } else { |
| 62: | $meta_key_price = 'property_price'; |
| 63: | } |
| 64: | |
| 65: | $sort_options = array( |
| 66: | 'price' => $meta_key_price, |
| 67: | 'date' => 'post_date', |
| 68: | ); |
| 69: | |
| 70: | $post_type = $attributes['post_type']; |
| 71: | |
| 72: | if ( ! is_array( $attributes['post_type'] ) ) { |
| 73: | $post_type = array_map( 'trim', explode( ',', $attributes['post_type'] ) ); |
| 74: | } |
| 75: | ob_start(); |
| 76: | $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; |
| 77: | $args = array( |
| 78: | 'post_type' => $post_type, |
| 79: | 'posts_per_page' => $attributes['limit'], |
| 80: | 'paged' => $paged, |
| 81: | ); |
| 82: | |
| 83: | |
| 84: | $args['meta_query'][] = array( |
| 85: | 'key' => 'property_under_offer', |
| 86: | 'value' => 'yes', |
| 87: | 'compare' => '!=', |
| 88: | ); |
| 89: | |
| 90: | |
| 91: | $args['meta_query'][] = array( |
| 92: | 'relation' => 'OR', |
| 93: | array( |
| 94: | 'key' => 'property_authority', |
| 95: | 'value' => 'auction', |
| 96: | ), |
| 97: | array( |
| 98: | 'key' => 'property_com_authority', |
| 99: | 'value' => 'auction', |
| 100: | ), |
| 101: | ); |
| 102: | |
| 103: | if ( ! empty( $attributes['location'] ) ) { |
| 104: | if ( ! is_array( $attributes['location'] ) ) { |
| 105: | $location = explode( ',', $attributes['location'] ); |
| 106: | $location = array_map( 'trim', $location ); |
| 107: | |
| 108: | $args['tax_query'][] = array( |
| 109: | 'taxonomy' => 'location', |
| 110: | 'field' => 'slug', |
| 111: | 'terms' => $location, |
| 112: | ); |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | if ( ! empty( $attributes['status'] ) ) { |
| 117: | if ( ! is_array( $attributes['status'] ) ) { |
| 118: | $status = explode( ',', $attributes['status'] ); |
| 119: | $status = array_map( 'trim', $status ); |
| 120: | |
| 121: | $args['meta_query'][] = array( |
| 122: | 'key' => 'property_status', |
| 123: | 'value' => $status, |
| 124: | 'compare' => 'IN', |
| 125: | ); |
| 126: | |
| 127: | add_filter( 'epl_sorting_options', 'epl_sorting_options_callback' ); |
| 128: | } |
| 129: | } |
| 130: | |
| 131: | if ( ! empty( $attributes['sortby'] ) ) { |
| 132: | |
| 133: | if ( 'price' === $attributes['sortby'] ) { |
| 134: | $args['orderby'] = 'meta_value_num'; |
| 135: | $args['meta_key'] = $meta_key_price; |
| 136: | } elseif ( 'status' === $attributes['sortby'] ) { |
| 137: | $args['orderby'] = 'meta_value'; |
| 138: | $args['meta_key'] = 'property_status'; |
| 139: | } else { |
| 140: | $args['orderby'] = 'post_date'; |
| 141: | } |
| 142: | $args['order'] = $attributes['sort_order']; |
| 143: | } |
| 144: | |
| 145: | $args['instance_id'] = $attributes['instance_id']; |
| 146: | |
| 147: | $args = epl_add_orderby_args( $args, 'shortcode', 'listing_auction' ); |
| 148: | |
| 149: | |
| 150: | $args = apply_filters( 'epl_shortcode_listing_auction_args', $args, $attributes ); |
| 151: | |
| 152: | $query_open = new WP_Query( $args ); |
| 153: | |
| 154: | if ( is_object( $attributes['query_object'] ) ) { |
| 155: | $query_open = $attributes['query_object']; |
| 156: | } |
| 157: | |
| 158: | if ( $query_open->have_posts() ) { ?> |
| 159: | <div class="loop epl-shortcode"> |
| 160: | <div class="loop-content epl-shortcode-listing-auction <?php echo ' ' . esc_attr( epl_template_class( $attributes['template'], 'archive' ) ) . ' ' . esc_attr( $attributes['class'] ); ?>"> |
| 161: | <?php |
| 162: | if ( 'on' === $attributes['tools_top'] ) { |
| 163: | do_action( 'epl_property_loop_start', $attributes ); |
| 164: | } |
| 165: | while ( $query_open->have_posts() ) { |
| 166: | $query_open->the_post(); |
| 167: | $template = str_replace( '_', '-', $attributes['template'] ); |
| 168: | epl_property_blog( $template ); |
| 169: | } |
| 170: | if ( 'on' === $attributes['tools_bottom'] ) { |
| 171: | do_action( 'epl_property_loop_end' ); |
| 172: | } |
| 173: | ?> |
| 174: | </div> |
| 175: | <div class="loop-footer"> |
| 176: | <?php |
| 177: | if ( 'on' === $attributes['pagination'] ) { |
| 178: | do_action( 'epl_pagination', array( 'query' => $query_open ) ); |
| 179: | } |
| 180: | ?> |
| 181: | </div> |
| 182: | </div> |
| 183: | <?php |
| 184: | } else { |
| 185: | do_action( 'epl_shortcode_results_message', 'auction' ); |
| 186: | } |
| 187: | wp_reset_postdata(); |
| 188: | return ob_get_clean(); |
| 189: | } |
| 190: | add_shortcode( 'listing_auction', 'epl_shortcode_listing_auction_callback' ); |
| 191: | |