| 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: | function epl_shortcode_property_open_callback( $atts ) { |
| 34: | $property_types = epl_get_active_post_types(); |
| 35: | if ( ! empty( $property_types ) ) { |
| 36: | $property_types = array_keys( $property_types ); |
| 37: | } |
| 38: | |
| 39: | $attributes = shortcode_atts( |
| 40: | array( |
| 41: | 'post_type' => $property_types, |
| 42: | 'limit' => '-1', |
| 43: | 'template' => false, |
| 44: | 'location' => '', |
| 45: | 'tools_top' => 'off', |
| 46: | 'tools_bottom' => 'off', |
| 47: | 'sortby' => '', |
| 48: | 'sort_order' => 'DESC', |
| 49: | 'pagination' => 'on', |
| 50: | 'instance_id' => '1', |
| 51: | 'class' => '', |
| 52: | |
| 53: | ), |
| 54: | $atts |
| 55: | ); |
| 56: | |
| 57: | $post_type = $attributes['post_type']; |
| 58: | $limit = $attributes['limit']; |
| 59: | $template = $attributes['template']; |
| 60: | $location = $attributes['location']; |
| 61: | $tools_top = $attributes['tools_top']; |
| 62: | $tools_bottom = $attributes['tools_bottom']; |
| 63: | $sortby = $attributes['sortby']; |
| 64: | $sort_order = $attributes['sort_order']; |
| 65: | $pagination = $attributes['pagination']; |
| 66: | $instance_id = $attributes['instance_id']; |
| 67: | $class = $attributes['class']; |
| 68: | |
| 69: | if ( is_string( $post_type ) && 'rental' === $post_type ) { |
| 70: | $meta_key_price = 'property_rent'; |
| 71: | } else { |
| 72: | $meta_key_price = 'property_price'; |
| 73: | } |
| 74: | |
| 75: | $sort_options = array( |
| 76: | 'price' => $meta_key_price, |
| 77: | 'date' => 'post_date', |
| 78: | ); |
| 79: | |
| 80: | ob_start(); |
| 81: | if ( ! is_array( $post_type ) ) { |
| 82: | $post_type = array_map( 'trim', explode( ',', $post_type ) ); |
| 83: | } |
| 84: | |
| 85: | $args = array( |
| 86: | 'post_type' => $post_type, |
| 87: | 'posts_per_page' => $limit, |
| 88: | 'meta_key' => 'property_inspection_times', |
| 89: | 'meta_query' => array( |
| 90: | array( |
| 91: | 'key' => 'property_inspection_times', |
| 92: | 'value' => '^\s*$', |
| 93: | 'compare' => 'NOT REGEXP', |
| 94: | ), |
| 95: | array( |
| 96: | 'key' => 'property_status', |
| 97: | 'value' => array( 'leased', 'sold' ), |
| 98: | 'compare' => 'NOT IN', |
| 99: | ), |
| 100: | ), |
| 101: | ); |
| 102: | |
| 103: | if ( ! empty( $location ) ) { |
| 104: | if ( ! is_array( $location ) ) { |
| 105: | $location = explode( ',', $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 ( '' !== $sortby ) { |
| 117: | |
| 118: | if ( 'price' === $sortby ) { |
| 119: | $args['orderby'] = 'meta_value_num'; |
| 120: | $args['meta_key'] = $meta_key_price; |
| 121: | } elseif ( 'status' === $sortby ) { |
| 122: | $args['orderby'] = 'meta_value'; |
| 123: | $args['meta_key'] = 'property_status'; |
| 124: | } else { |
| 125: | $args['orderby'] = 'post_date'; |
| 126: | } |
| 127: | $args['order'] = $sort_order; |
| 128: | } |
| 129: | |
| 130: | $args['instance_id'] = $attributes['instance_id']; |
| 131: | |
| 132: | $args = epl_add_orderby_args( $args, 'shortcode', 'listing_open' ); |
| 133: | |
| 134: | |
| 135: | $args = apply_filters( 'epl_shortcode_listing_open_args', $args, $attributes ); |
| 136: | |
| 137: | $query_open = new WP_Query( $args ); |
| 138: | if ( $query_open->have_posts() ) { ?> |
| 139: | <div class="loop epl-shortcode"> |
| 140: | <div class="loop-content epl-shortcode-listing-open <?php echo ' ' . esc_attr( epl_template_class( $template, 'archive' ) ) . ' ' . esc_attr( $attributes['class'] ); ?>"> |
| 141: | <?php |
| 142: | if ( 'on' === $tools_top ) { |
| 143: | do_action( 'epl_property_loop_start', $attributes ); |
| 144: | } |
| 145: | while ( $query_open->have_posts() ) { |
| 146: | $query_open->the_post(); |
| 147: | |
| 148: | $template = str_replace( '_', '-', $template ); |
| 149: | epl_property_blog( $template ); |
| 150: | } |
| 151: | if ( 'on' === $tools_bottom ) { |
| 152: | do_action( 'epl_property_loop_end' ); |
| 153: | } |
| 154: | |
| 155: | ?> |
| 156: | </div> |
| 157: | <div class="loop-footer"> |
| 158: | <?php |
| 159: | if ( 'on' === $pagination ) { |
| 160: | do_action( 'epl_pagination', array( 'query' => $query_open ) ); |
| 161: | } |
| 162: | ?> |
| 163: | </div> |
| 164: | </div> |
| 165: | <?php |
| 166: | } else { |
| 167: | do_action( 'epl_shortcode_results_message', 'open' ); |
| 168: | } |
| 169: | wp_reset_postdata(); |
| 170: | return ob_get_clean(); |
| 171: | } |
| 172: | add_shortcode( 'home_open_list', 'epl_shortcode_property_open_callback' ); |
| 173: | add_shortcode( 'listing_open', 'epl_shortcode_property_open_callback' ); |
| 174: | |