| 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_tax_feature_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: | 'feature' => '', |
| 45: | 'feature_id' => '', |
| 46: | 'limit' => '10', |
| 47: | 'offset' => '', |
| 48: | 'template' => false, |
| 49: | 'location' => '', |
| 50: | 'tools_top' => 'off', |
| 51: | 'tools_bottom' => 'off', |
| 52: | 'sortby' => '', |
| 53: | 'sort_order' => 'DESC', |
| 54: | 'pagination' => 'on', |
| 55: | 'instance_id' => '1', |
| 56: | 'class' => '', |
| 57: | ), |
| 58: | $atts |
| 59: | ); |
| 60: | |
| 61: | $post_type = $attributes['post_type']; |
| 62: | $status = $attributes['status']; |
| 63: | $limit = $attributes['limit']; |
| 64: | $feature = $attributes['feature']; |
| 65: | $feature_id = $attributes['feature_id']; |
| 66: | $offset = $attributes['offset']; |
| 67: | $template = $attributes['template']; |
| 68: | $location = $attributes['location']; |
| 69: | $tools_top = $attributes['tools_top']; |
| 70: | $tools_bottom = $attributes['tools_bottom']; |
| 71: | $sortby = $attributes['sortby']; |
| 72: | $sort_order = $attributes['sort_order']; |
| 73: | $pagination = $attributes['pagination']; |
| 74: | $instance_id = $attributes['instance_id']; |
| 75: | $class = $attributes['class']; |
| 76: | |
| 77: | if ( empty( $post_type ) ) { |
| 78: | return; |
| 79: | } |
| 80: | |
| 81: | if ( is_string( $post_type ) && 'rental' === $post_type ) { |
| 82: | $meta_key_price = 'property_rent'; |
| 83: | } else { |
| 84: | $meta_key_price = 'property_price'; |
| 85: | } |
| 86: | |
| 87: | $sort_options = array( |
| 88: | 'price' => $meta_key_price, |
| 89: | 'date' => 'post_date', |
| 90: | ); |
| 91: | |
| 92: | if ( ! is_array( $post_type ) ) { |
| 93: | $post_type = array_map( 'trim', explode( ',', $post_type ) ); |
| 94: | } |
| 95: | ob_start(); |
| 96: | |
| 97: | $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; |
| 98: | $args = array( |
| 99: | 'post_type' => $post_type, |
| 100: | 'posts_per_page' => $limit, |
| 101: | 'paged' => $paged, |
| 102: | ); |
| 103: | |
| 104: | |
| 105: | if ( ! empty( $offset ) ) { |
| 106: | $args['offset'] = $offset; |
| 107: | $pagination = 'off'; |
| 108: | } |
| 109: | |
| 110: | if ( ! empty( $feature ) ) { |
| 111: | if ( ! is_array( $feature ) ) { |
| 112: | $feature = explode( ',', $feature ); |
| 113: | $feature = array_map( 'trim', $feature ); |
| 114: | |
| 115: | $args['tax_query'][] = array( |
| 116: | 'taxonomy' => 'tax_feature', |
| 117: | 'field' => 'slug', |
| 118: | 'terms' => $feature, |
| 119: | ); |
| 120: | } |
| 121: | } |
| 122: | |
| 123: | if ( ! empty( $feature_id ) ) { |
| 124: | if ( ! is_array( $feature_id ) ) { |
| 125: | $feature_id = explode( ',', $feature_id ); |
| 126: | $feature_id = array_map( 'trim', $feature_id ); |
| 127: | |
| 128: | $args['tax_query'][] = array( |
| 129: | 'taxonomy' => 'tax_feature', |
| 130: | 'field' => 'id', |
| 131: | 'terms' => $feature_id, |
| 132: | ); |
| 133: | } |
| 134: | } |
| 135: | |
| 136: | if ( ! empty( $location ) ) { |
| 137: | if ( ! is_array( $location ) ) { |
| 138: | $location = explode( ',', $location ); |
| 139: | $location = array_map( 'trim', $location ); |
| 140: | |
| 141: | $args['tax_query'][] = array( |
| 142: | 'taxonomy' => 'location', |
| 143: | 'field' => 'slug', |
| 144: | 'terms' => $location, |
| 145: | ); |
| 146: | } |
| 147: | } |
| 148: | |
| 149: | if ( ! empty( $status ) ) { |
| 150: | if ( ! is_array( $status ) ) { |
| 151: | $status = explode( ',', $status ); |
| 152: | $status = array_map( 'trim', $status ); |
| 153: | |
| 154: | $args['meta_query'][] = array( |
| 155: | 'key' => 'property_status', |
| 156: | 'value' => $status, |
| 157: | 'compare' => 'IN', |
| 158: | ); |
| 159: | } |
| 160: | } |
| 161: | if ( ! empty( $sortby ) ) { |
| 162: | |
| 163: | if ( 'price' === $sortby ) { |
| 164: | $args['orderby'] = 'meta_value_num'; |
| 165: | $args['meta_key'] = $meta_key_price; |
| 166: | } elseif ( 'status' === $sortby ) { |
| 167: | $args['orderby'] = 'meta_value'; |
| 168: | $args['meta_key'] = 'property_status'; |
| 169: | } else { |
| 170: | $args['orderby'] = 'post_date'; |
| 171: | } |
| 172: | $args['order'] = $sort_order; |
| 173: | } |
| 174: | |
| 175: | $args['instance_id'] = $attributes['instance_id']; |
| 176: | |
| 177: | $args = epl_add_orderby_args( $args, 'shortcode', 'listing_feature' ); |
| 178: | |
| 179: | |
| 180: | $args = apply_filters( 'epl_shortcode_listing_feature_args', $args, $attributes ); |
| 181: | |
| 182: | $query_open = new WP_Query( $args ); |
| 183: | if ( $query_open->have_posts() ) { ?> |
| 184: | <div class="loop epl-shortcode"> |
| 185: | <div class="loop-content epl-shortcode-listing-feature <?php echo ' ' . esc_attr( epl_template_class( $template, 'archive' ) ) . ' ' . esc_attr( $attributes['class'] ); ?>"> |
| 186: | <?php |
| 187: | if ( 'on' === $tools_top ) { |
| 188: | do_action( 'epl_property_loop_start', $attributes ); |
| 189: | } |
| 190: | while ( $query_open->have_posts() ) { |
| 191: | $query_open->the_post(); |
| 192: | $template = str_replace( '_', '-', $template ); |
| 193: | epl_property_blog( $template ); |
| 194: | } |
| 195: | if ( 'on' === $tools_bottom ) { |
| 196: | do_action( 'epl_property_loop_end' ); |
| 197: | } |
| 198: | ?> |
| 199: | </div> |
| 200: | <div class="loop-footer"> |
| 201: | <?php |
| 202: | if ( 'on' === $pagination ) { |
| 203: | do_action( 'epl_pagination', array( 'query' => $query_open ) ); |
| 204: | } |
| 205: | ?> |
| 206: | </div> |
| 207: | </div> |
| 208: | <?php |
| 209: | } else { |
| 210: | do_action( 'epl_shortcode_results_message' ); |
| 211: | } |
| 212: | wp_reset_postdata(); |
| 213: | return ob_get_clean(); |
| 214: | } |
| 215: | add_shortcode( 'listing_feature', 'epl_shortcode_listing_tax_feature_callback' ); |
| 216: | |