| 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: | function epl_is_listing_results_page() { |
| 30: | global $wp_the_query; |
| 31: | |
| 32: | $is_results = ( function_exists( 'epl_is_search' ) && true === epl_is_search() ) || is_epl_core_post(); |
| 33: | |
| 34: | if ( ! $is_results && $wp_the_query instanceof WP_Query && ! $wp_the_query->is_singular() ) { |
| 35: | $is_results = $wp_the_query->is_post_type_archive( epl_get_core_post_types() ) |
| 36: | || $wp_the_query->is_tax( array( 'location', 'tax_feature', 'tax_business_listing' ) ) |
| 37: | || ( $wp_the_query->is_archive() && ! empty( $wp_the_query->posts ) && is_epl_core_post( get_post_type( $wp_the_query->posts[0] ) ) ); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | return (bool) apply_filters( 'epl_is_listing_results_page', $is_results ); |
| 48: | } |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | function epl_is_page_builder_preview() { |
| 60: | |
| 61: | $preview = isset( $_GET['elementor-preview'] ) || isset( $_GET['et_fb'] ) || isset( $_GET['vc_editable'] ) || isset( $_GET['fl_builder'] ) || isset( $_GET['ct_builder'] ) |
| 62: | || ( isset( $_GET['bricks'] ) && 'run' === $_GET['bricks'] ); |
| 63: | |
| 64: | if ( ! $preview && wp_doing_ajax() && isset( $_REQUEST['action'] ) && 'elementor_ajax' === $_REQUEST['action'] ) { |
| 65: | $preview = true; |
| 66: | } |
| 67: | |
| 68: | if ( ! $preview && class_exists( '\Elementor\Plugin' ) && isset( \Elementor\Plugin::$instance ) ) { |
| 69: | $elementor = \Elementor\Plugin::$instance; |
| 70: | |
| 71: | if ( isset( $elementor->editor ) && is_object( $elementor->editor ) && method_exists( $elementor->editor, 'is_edit_mode' ) && $elementor->editor->is_edit_mode() ) { |
| 72: | $preview = true; |
| 73: | } elseif ( isset( $elementor->preview ) && is_object( $elementor->preview ) && method_exists( $elementor->preview, 'is_preview_mode' ) && $elementor->preview->is_preview_mode() ) { |
| 74: | $preview = true; |
| 75: | } |
| 76: | } |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | return (bool) apply_filters( 'epl_is_page_builder_preview', $preview ); |
| 86: | } |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | function epl_listing_results_loop_callback( $atts ) { |
| 106: | |
| 107: | $attributes = shortcode_atts( |
| 108: | array( |
| 109: | 'tools_top' => 'off', |
| 110: | 'tools_bottom' => 'off', |
| 111: | 'pagination' => 'on', |
| 112: | 'template' => '', |
| 113: | 'class' => '', |
| 114: | 'title' => 'off', |
| 115: | 'preview_limit' => '', |
| 116: | 'instance_id' => '1', |
| 117: | ), |
| 118: | $atts |
| 119: | ); |
| 120: | |
| 121: | |
| 122: | $preview = false; |
| 123: | |
| 124: | if ( epl_is_listing_results_page() ) { |
| 125: | global $wp_query; |
| 126: | $query = $wp_query; |
| 127: | } elseif ( epl_is_page_builder_preview() || is_singular() ) { |
| 128: | |
| 129: | |
| 130: | |
| 131: | $preview = true; |
| 132: | $paged = max( 1, (int) get_query_var( 'paged' ), (int) get_query_var( 'page' ) ); |
| 133: | $args = array( |
| 134: | 'post_type' => array_keys( epl_get_active_post_types() ), |
| 135: | 'post_status' => 'publish', |
| 136: | 'posts_per_page' => epl_is_page_builder_preview() && '' !== $attributes['preview_limit'] ? (int) $attributes['preview_limit'] : (int) get_option( 'posts_per_page' ), |
| 137: | 'paged' => $paged, |
| 138: | 'instance_id' => sanitize_text_field( $attributes['instance_id'] ), |
| 139: | ); |
| 140: | $query = new WP_Query( epl_add_orderby_args( $args, 'shortcode', 'listing_results' ) ); |
| 141: | } else { |
| 142: | return ''; |
| 143: | } |
| 144: | |
| 145: | $template = str_replace( '_', '-', sanitize_key( $attributes['template'] ) ); |
| 146: | $wrapper_class = 'epl-shortcode-listing-results ' . epl_template_class( $template, 'archive' ); |
| 147: | if ( '' !== $attributes['class'] ) { |
| 148: | $wrapper_class .= ' ' . $attributes['class']; |
| 149: | } |
| 150: | |
| 151: | ob_start(); |
| 152: | |
| 153: | if ( $query->have_posts() ) : |
| 154: | ?> |
| 155: | |
| 156: | <?php if ( 'on' === $attributes['title'] ) : ?> |
| 157: | <header class="archive-header entry-header loop-header"> |
| 158: | <h4 class="archive-title loop-title"> |
| 159: | <?php |
| 160: | if ( $preview ) { |
| 161: | |
| 162: | esc_html_e( 'Listings', 'easy-property-listings' ); |
| 163: | } else { |
| 164: | do_action( 'epl_the_archive_title' ); |
| 165: | } |
| 166: | ?> |
| 167: | </h4> |
| 168: | </header> |
| 169: | <?php endif; ?> |
| 170: | |
| 171: | <div class="<?php echo esc_attr( $wrapper_class ); ?>"> |
| 172: | <?php |
| 173: | if ( 'on' === $attributes['tools_top'] ) { |
| 174: | do_action( 'epl_property_loop_start', $attributes ); |
| 175: | } |
| 176: | ?> |
| 177: | |
| 178: | <?php |
| 179: | while ( $query->have_posts() ) : |
| 180: | $query->the_post(); |
| 181: | if ( '' === $template ) { |
| 182: | do_action( 'epl_property_blog' ); |
| 183: | } else { |
| 184: | epl_property_blog( $template ); |
| 185: | } |
| 186: | endwhile; |
| 187: | ?> |
| 188: | |
| 189: | <?php |
| 190: | if ( 'on' === $attributes['tools_bottom'] ) { |
| 191: | do_action( 'epl_property_loop_end' ); |
| 192: | } |
| 193: | ?> |
| 194: | </div> |
| 195: | |
| 196: | <div class="loop-footer"> |
| 197: | <!-- Previous/Next page navigation --> |
| 198: | <div class="loop-utility clearfix"> |
| 199: | <?php |
| 200: | if ( 'on' === $attributes['pagination'] ) { |
| 201: | if ( $preview ) { |
| 202: | do_action( 'epl_pagination', array( 'query' => $query ) ); |
| 203: | } else { |
| 204: | do_action( 'epl_pagination' ); |
| 205: | } |
| 206: | } |
| 207: | ?> |
| 208: | </div> |
| 209: | </div> |
| 210: | |
| 211: | <?php else : ?> |
| 212: | |
| 213: | <?php do_action( 'epl_property_search_not_found' ); ?> |
| 214: | |
| 215: | <?php |
| 216: | endif; |
| 217: | |
| 218: | if ( $preview ) { |
| 219: | wp_reset_postdata(); |
| 220: | } |
| 221: | |
| 222: | return ob_get_clean(); |
| 223: | } |
| 224: | add_shortcode( 'listing_results', 'epl_listing_results_loop_callback' ); |
| 225: | |