function epl_get_post_count($type = '', $meta_key, $meta_value, $author_id = '')
{
    global $wpdb;
    $sql = "\n\t\tSELECT count( Distinct p.ID ) AS count\n\t\tFROM {$wpdb->prefix}posts AS p\n\t\tINNER JOIN {$wpdb->postmeta} pm  ON (p.ID = pm.post_id)\n\t\tINNER JOIN {$wpdb->postmeta} pm2  ON (p.ID = pm2.post_id) \n\t\tWHERE p.post_status = 'publish' ";
    if ($type == '') {
        $epl_posts = epl_get_active_post_types();
        $epl_posts = '"' . implode('","', array_keys($epl_posts)) . '"';
        $sql .= " AND p.post_type IN ( {$epl_posts} )";
    } else {
        $sql .= " AND p.post_type = '{$type}'";
    }
    if ($author_id != '') {
        $user_info = get_userdata($author_id);
        $sql .= " AND (\n\t\t\t\t\t\tp.post_author =  {$author_id}\n\t\t\t\t\t\tOR (\n\t\t\t\t\t\t\tpm2.meta_key \t= 'property_second_agent' \n\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\tpm2.meta_value \t= '{$user_info->user_login}'\n\t\t\t\t\t\t)\n\t\t\t\t\t)";
    }
    $sql .= "\t\n\t\tAND p.ID = pm.post_id\n\t\tAND pm.meta_key = '{$meta_key}'\n\t\tAND pm.meta_value = '{$meta_value}'\n\t";
    $count = $wpdb->get_row($sql);
    return $count->count;
}
Example #2
0
 function epl_all_post_types()
 {
     $epl_posts = epl_get_active_post_types();
     $epl_posts = array_keys($epl_posts);
     return apply_filters('epl_additional_post_types', $epl_posts);
 }
function epl_search_pre_get_posts($query)
{
    if (is_admin() || !$query->is_main_query()) {
        return;
    }
    if (epl_is_search()) {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $query->init();
        $query->set('posts_per_page', get_option('posts_per_page'));
        $query->set('paged', $paged);
        extract($_REQUEST);
        if (isset($property_id)) {
            if (is_numeric($property_id)) {
            } else {
                $query->set('epl_post_title', sanitize_text_field($property_id));
            }
        }
        if (isset($property_agent)) {
            $property_agent = sanitize_title_with_dashes($property_agent);
            if ($property_agent = get_user_by('slug', $property_agent)) {
                $query->set('post_author', $property_agent->ID);
            }
        }
        if (isset($post_type) && !empty($post_type)) {
            $query->set('post_type', $post_type);
        } else {
            $epl_post_types = epl_get_active_post_types();
            if (!empty($epl_post_types)) {
                $epl_post_types = array_keys($epl_post_types);
                $query->set('post_type', $epl_post_types);
            }
        }
        $epl_meta_query = array();
        $epl_search_form_fields = epl_search_widget_fields_frontend($post_type, $property_status);
        foreach ($epl_search_form_fields as $epl_search_form_field) {
            if (isset($epl_search_form_field['query'])) {
                if ($epl_search_form_field['query']['query'] == 'meta') {
                    $this_meta_query = array();
                    if (isset($epl_search_form_field['query']['multiple']) && $epl_search_form_field['query']['multiple'] == true) {
                        if (isset(${$epl_search_form_field['meta_key']}) && !empty(${$epl_search_form_field['meta_key']})) {
                            $this_meta_query['relation'] = isset($epl_search_form_field['query']['relation']) ? $epl_search_form_field['query']['relation'] : 'OR';
                            foreach ($epl_search_form_field['query']['sub_queries'] as $sub_query) {
                                $this_sub_query = array('key' => $sub_query['key'], 'value' => ${$epl_search_form_field['meta_key']}, 'type' => $sub_query['type'], 'compare' => $sub_query['compare']);
                                $this_meta_query[] = $this_sub_query;
                            }
                            $epl_meta_query[] = $this_meta_query;
                        }
                    } else {
                        $query_meta_key = isset($epl_search_form_field['query']['key']) ? $epl_search_form_field['query']['key'] : $epl_search_form_field['meta_key'];
                        if ($query_meta_key == 'property_unique_id' && isset(${$epl_search_form_field['meta_key']}) && !is_numeric(${$epl_search_form_field['meta_key']})) {
                            continue;
                        }
                        if (isset(${$epl_search_form_field['meta_key']}) && !empty(${$epl_search_form_field['meta_key']})) {
                            $this_meta_query = array('key' => $query_meta_key, 'value' => ${$epl_search_form_field['meta_key']});
                            isset($epl_search_form_field['query']['compare']) ? $this_meta_query['compare'] = $epl_search_form_field['query']['compare'] : '';
                            isset($epl_search_form_field['query']['type']) ? $this_meta_query['type'] = $epl_search_form_field['query']['type'] : '';
                            isset($epl_search_form_field['query']['value']) ? $this_meta_query['value'] = $epl_search_form_field['query']['value'] : '';
                            $epl_meta_query[] = $this_meta_query;
                        }
                    }
                }
            }
        }
        if (!empty($epl_meta_query)) {
            $query->set('meta_query', $epl_meta_query);
        }
        $tax_query = array();
        if (isset($property_location) && !empty($property_location)) {
            $tax_query[] = array('taxonomy' => 'location', 'field' => 'id', 'terms' => $property_location);
        }
        if (!empty($tax_query)) {
            $query->set('tax_query', $tax_query);
        }
        $query->parse_query();
    }
}
/**
 * This shortcode allows for you to specify the property type(s) using 
 * [listing post_type="property,rental" status="current,sold,leased" template="default"] option. You can also 
 * limit the number of entries that display. using  [listing limit="5"]
 */
function epl_shortcode_listing_callback($atts)
{
    $property_types = epl_get_active_post_types();
    if (!empty($property_types)) {
        $property_types = array_keys($property_types);
    }
    extract(shortcode_atts(array('post_type' => $property_types, 'status' => array('current', 'sold', 'leased'), 'limit' => '10', 'template' => false, 'location' => '', 'tools_top' => 'off', 'tools_bottom' => 'off', 'sortby' => '', 'sort_order' => 'DESC', 'query_object' => ''), $atts));
    if (is_string($post_type) && $post_type == 'rental') {
        $meta_key_price = 'property_rent';
    } else {
        $meta_key_price = 'property_price';
    }
    $sort_options = array('price' => $meta_key_price, 'date' => 'post_date');
    if (!is_array($post_type)) {
        $post_type = array_map('trim', explode(',', $post_type));
    }
    ob_start();
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array('post_type' => $post_type, 'posts_per_page' => $limit, 'paged' => $paged);
    if (!empty($location)) {
        if (!is_array($location)) {
            $location = explode(",", $location);
            $location = array_map('trim', $location);
            $args['tax_query'][] = array('taxonomy' => 'location', 'field' => 'slug', 'terms' => $location);
        }
    }
    if (!empty($status)) {
        if (!is_array($status)) {
            $status = explode(",", $status);
            $status = array_map('trim', $status);
            $args['meta_query'][] = array('key' => 'property_status', 'value' => $status, 'compare' => 'IN');
            add_filter('epl_sorting_options', 'epl_sorting_options_callback');
        }
    }
    if ($sortby != '') {
        if ($sortby == 'price') {
            $args['orderby'] = 'meta_value_num';
            $args['meta_key'] = $meta_key_price;
        } else {
            $args['orderby'] = 'post_date';
            $args['order'] = 'DESC';
        }
        $args['order'] = $sort_order;
    }
    if (isset($_GET['sortby'])) {
        $orderby = sanitize_text_field(trim($_GET['sortby']));
        if ($orderby == 'high') {
            $args['orderby'] = 'meta_value_num';
            $args['meta_key'] = $meta_key_price;
            $args['order'] = 'DESC';
        } elseif ($orderby == 'low') {
            $args['orderby'] = 'meta_value_num';
            $args['meta_key'] = $meta_key_price;
            $args['order'] = 'ASC';
        } elseif ($orderby == 'new') {
            $args['orderby'] = 'post_date';
            $args['order'] = 'DESC';
        } elseif ($orderby == 'old') {
            $args['orderby'] = 'post_date';
            $args['order'] = 'ASC';
        } elseif ($orderby == 'status_desc') {
            $args['orderby'] = 'meta_value';
            $args['meta_key'] = 'property_status';
            $args['order'] = 'DESC';
        } elseif ($orderby == 'status_asc') {
            $args['orderby'] = 'meta_value';
            $args['meta_key'] = 'property_status';
            $args['order'] = 'ASC';
        }
    }
    $query_open = new WP_Query($args);
    if (is_object($query_object)) {
        $query_open = $query_object;
    }
    if ($query_open->have_posts()) {
        ?>
		<div class="loop epl-shortcode">
			<div class="loop-content epl-shortcode-listing <?php 
        echo epl_template_class($template);
        ?>
">
				<?php 
        if ($tools_top == 'on') {
            do_action('epl_property_loop_start');
        }
        while ($query_open->have_posts()) {
            $query_open->the_post();
            $template = str_replace('_', '-', $template);
            epl_property_blog($template);
        }
        if ($tools_bottom == 'on') {
            do_action('epl_property_loop_end');
        }
        ?>
			</div>
			<div class="loop-footer">
					<?php 
        do_action('epl_pagination', array('query' => $query_open));
        ?>
			</div>
		</div>
		<?php 
    } else {
        echo '<h3>' . __('Nothing found, please check back later.', 'epl') . '</h3>';
    }
    wp_reset_postdata();
    return ob_get_clean();
}
    function form($instance)
    {
        $defaults = array('title' => '', 'post_type' => array('property'), 'style' => 'default', 'property_status' => 'any', 'search_location' => 'on', 'search_city' => 'off', 'search_state' => 'off', 'search_country' => 'off', 'search_postcode' => 'off', 'search_house_category' => 'on', 'search_price' => 'on', 'search_bed' => 'on', 'search_bath' => 'on', 'search_rooms' => 'off', 'search_car' => 'on', 'search_other' => 'on', 'search_id' => 'off', 'search_land_area' => 'off', 'search_building_area' => 'off', 'submit_label' => __('Find me a Property!', 'epl'));
        $instance = wp_parse_args((array) $instance, $defaults);
        $title = esc_attr($instance['title']);
        $post_types = $instance['post_type'];
        $property_status = esc_attr($instance['property_status']);
        $style = esc_attr($instance['style']);
        $search_location = esc_attr($instance['search_location']);
        $search_city = esc_attr($instance['search_city']);
        $search_state = esc_attr($instance['search_state']);
        $search_country = esc_attr($instance['search_country']);
        $search_postcode = esc_attr($instance['search_postcode']);
        $search_house_category = esc_attr($instance['search_house_category']);
        $search_price = esc_attr($instance['search_price']);
        $search_bed = esc_attr($instance['search_bed']);
        $search_bath = esc_attr($instance['search_bath']);
        $search_rooms = esc_attr($instance['search_rooms']);
        $search_car = esc_attr($instance['search_car']);
        $search_id = esc_attr($instance['search_id']);
        $search_other = esc_attr($instance['search_other']);
        $search_land_area = esc_attr($instance['search_land_area']);
        $search_building_area = esc_attr($instance['search_building_area']);
        $submit_label = esc_attr($instance['submit_label']);
        ?>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', 'epl');
        ?>
</label> 
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" />
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('style');
        ?>
"><?php 
        _e('Style', 'epl');
        ?>
</label> 
			<select class="widefat" id="<?php 
        echo $this->get_field_id('style');
        ?>
" name="<?php 
        echo $this->get_field_name('style');
        ?>
">
				<?php 
        $status_list = array('default' => __('Default', 'epl'), 'wide' => __('Wide', 'epl'), 'slim' => __('Slim', 'epl'));
        foreach ($status_list as $k => $v) {
            $selected = '';
            if (isset($style) && $k == $style) {
                $selected = 'selected="selected"';
            }
            echo '<option value="' . $k . '" ' . $selected . '>' . __($v, 'epl') . '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('post_type');
        ?>
"><?php 
        _e('Listing Type, hold CTRL to select multiple and enable tabs', 'epl');
        ?>
</label> 
			<select multiple class="widefat" id="<?php 
        echo $this->get_field_id('post_type');
        ?>
" name="<?php 
        echo $this->get_field_name('post_type');
        ?>
[]">
				<?php 
        $supported_post_types = epl_get_active_post_types();
        if (!empty($supported_post_types)) {
            foreach ($supported_post_types as $k => $v) {
                $selected = '';
                if (in_array($k, $post_types)) {
                    $selected = 'selected="selected"';
                }
                echo '<option value="' . $k . '" ' . $selected . '>' . __($v, 'epl') . '</option>';
            }
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('property_status');
        ?>
"><?php 
        _e('Status:', 'epl');
        ?>
</label> 
			<select class="widefat" id="<?php 
        echo $this->get_field_id('property_status');
        ?>
" name="<?php 
        echo $this->get_field_name('property_status');
        ?>
">
				<?php 
        $status_list = array('' => __('Any', 'epl'), 'current' => __('Current', 'epl'), 'sold' => apply_filters('epl_sold_label_status_filter', __('Sold', 'epl')), 'leased' => apply_filters('epl_leased_label_status_filter', __('Leased', 'epl')));
        foreach ($status_list as $k => $v) {
            $selected = '';
            if (isset($property_status) && $k == $property_status) {
                $selected = 'selected="selected"';
            }
            echo '<option value="' . $k . '" ' . $selected . '>' . __($v, 'epl') . '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_id');
        ?>
" name="<?php 
        echo $this->get_field_name('search_id');
        ?>
" type="checkbox" <?php 
        if (isset($search_id) && $search_id == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_id');
        ?>
"><?php 
        _e('Property ID', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_location');
        ?>
" name="<?php 
        echo $this->get_field_name('search_location');
        ?>
" type="checkbox" <?php 
        if (isset($search_location) && $search_location == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_location');
        ?>
"><?php 
        _e('Location', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_city');
        ?>
" name="<?php 
        echo $this->get_field_name('search_city');
        ?>
" type="checkbox" <?php 
        if (isset($search_city) && $search_city == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_city');
        ?>
"><?php 
        _e('City', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_state');
        ?>
" name="<?php 
        echo $this->get_field_name('search_state');
        ?>
" type="checkbox" <?php 
        if (isset($search_state) && $search_state == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_state');
        ?>
"><?php 
        _e('State', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_country');
        ?>
" name="<?php 
        echo $this->get_field_name('search_country');
        ?>
" type="checkbox" <?php 
        if (isset($search_country) && $search_country == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_country');
        ?>
"><?php 
        _e('Country', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_postcode');
        ?>
" name="<?php 
        echo $this->get_field_name('search_postcode');
        ?>
" type="checkbox" <?php 
        if (isset($search_postcode) && $search_postcode == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_postcode');
        ?>
"><?php 
        echo epl_display_label_postcode();
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_house_category');
        ?>
" name="<?php 
        echo $this->get_field_name('search_house_category');
        ?>
" type="checkbox" <?php 
        if (isset($search_house_category) && $search_house_category == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_house_category');
        ?>
"><?php 
        _e('House Category', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_price');
        ?>
" name="<?php 
        echo $this->get_field_name('search_price');
        ?>
" type="checkbox" <?php 
        if (isset($search_price) && $search_price == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_price');
        ?>
"><?php 
        _e('Price', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_bed');
        ?>
" name="<?php 
        echo $this->get_field_name('search_bed');
        ?>
" type="checkbox" <?php 
        if (isset($search_bed) && $search_bed == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_bed');
        ?>
"><?php 
        _e('Bedroom', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_bath');
        ?>
" name="<?php 
        echo $this->get_field_name('search_bath');
        ?>
" type="checkbox" <?php 
        if (isset($search_bath) && $search_bath == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_bath');
        ?>
"><?php 
        _e('Bathroom', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_rooms');
        ?>
" name="<?php 
        echo $this->get_field_name('search_rooms');
        ?>
" type="checkbox" <?php 
        if (isset($search_rooms) && $search_rooms == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_rooms');
        ?>
"><?php 
        _e('Rooms', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_car');
        ?>
" name="<?php 
        echo $this->get_field_name('search_car');
        ?>
" type="checkbox" <?php 
        if (isset($search_car) && $search_car == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_car');
        ?>
"><?php 
        _e('Car', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_land_area');
        ?>
" name="<?php 
        echo $this->get_field_name('search_land_area');
        ?>
" type="checkbox" <?php 
        if (isset($search_land_area) && $search_land_area == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_land_area');
        ?>
"><?php 
        _e('Land Area', 'epl');
        ?>
</label>
		</p>
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_building_area');
        ?>
" name="<?php 
        echo $this->get_field_name('search_building_area');
        ?>
" type="checkbox" <?php 
        if (isset($search_building_area) && $search_building_area == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_building_area');
        ?>
"><?php 
        _e('Building Area', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<input id="<?php 
        echo $this->get_field_id('search_other');
        ?>
" name="<?php 
        echo $this->get_field_name('search_other');
        ?>
" type="checkbox" <?php 
        if (isset($search_other) && $search_other == 'on') {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('search_other');
        ?>
"><?php 
        _e('Other Search Options', 'epl');
        ?>
</label>
		</p>
		<p>
			<label for="<?php 
        echo $this->get_field_id('submit_label');
        ?>
"><?php 
        _e('Submit Label', 'epl');
        ?>
</label> 
			<input class="widefat" id="<?php 
        echo $this->get_field_id('submit_label');
        ?>
" name="<?php 
        echo $this->get_field_name('submit_label');
        ?>
" type="text" value="<?php 
        echo $submit_label;
        ?>
" />
		</p>
		<?php 
    }
    function form($instance)
    {
        $defaults = array('title' => '', 'types' => 'property', 'featured' => 0, 'status' => 'any', 'display' => 'image', 'image' => 'thumbnail', 'archive' => 0, 'order_rand' => 0, 'd_title' => 0, 'more_text' => __('Read More', 'epl'), 'd_excerpt' => 'off', 'd_suburb' => 'on', 'd_street' => 'on', 'd_price' => 'on', 'd_more' => 'on', 'd_icons' => 'none', 'p_number' => 1, 'p_skip' => 0);
        $instance = wp_parse_args((array) $instance, $defaults);
        $title = esc_attr($instance['title']);
        $types = esc_attr($instance['types']);
        $featured = esc_attr($instance['featured']);
        $status = esc_attr($instance['status']);
        $display = esc_attr($instance['display']);
        $image = esc_attr($instance['image']);
        $archive = esc_attr($instance['archive']);
        $d_title = esc_attr($instance['d_title']);
        $more_text = esc_attr($instance['more_text']);
        $d_excerpt = esc_attr($instance['d_excerpt']);
        $d_suburb = esc_attr($instance['d_suburb']);
        $d_street = esc_attr($instance['d_street']);
        $d_price = esc_attr($instance['d_price']);
        $d_more = esc_attr($instance['d_more']);
        $d_icons = esc_attr($instance['d_icons']);
        $p_number = esc_attr($instance['p_number']);
        $p_skip = esc_attr($instance['p_skip']);
        $order_rand = esc_attr($instance['order_rand']);
        ?>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'epl');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" />
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('types');
        ?>
"><?php 
        _e('Property Type', 'epl');
        ?>
</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('types');
        ?>
" name="<?php 
        echo $this->get_field_name('types');
        ?>
 ">
				<?php 
        $options = epl_get_active_post_types();
        if (!empty($options)) {
            foreach ($options as $k => $v) {
                echo '<option value="' . $k . '" id="' . $k . '"', $instance['types'] == $k ? ' selected="selected"' : '', '>', __($v, 'epl'), '</option>';
            }
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('status');
        ?>
"><?php 
        _e('Property Status', 'epl');
        ?>
</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('status');
        ?>
" name="<?php 
        echo $this->get_field_name('status');
        ?>
 ">
				<?php 
        $options = array('Any', 'Current', 'Sold', 'Leased');
        foreach ($options as $option) {
            echo '<option value="' . $option . '" id="' . $option . '"', $instance['status'] == $option ? ' selected="selected"' : '', '>', __($option, 'epl'), '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('display');
        ?>
"><?php 
        _e('Display Style', 'epl');
        ?>
</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('display');
        ?>
" name="<?php 
        echo $this->get_field_name('display');
        ?>
">
				<?php 
        /** usage **
         *
         *  add more templates to this by add key pair values to this array,
         *  key will be name of template example 'my-custom-widget-template.php' and value will be label for tpl, example 'My Template'
         */
        $options = apply_filters('epl_listing_widget_templates', array('image' => __('Image', 'epl'), 'image-only' => __('Image Only', 'epl'), 'list' => __('List', 'epl')));
        foreach ($options as $option_key => $option_label) {
            echo '<option value="' . $option_key . '" id="' . $option_key . '"', $instance['display'] == $option_key ? ' selected="selected"' : '', '>', __($option_label, 'epl'), '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('image');
        ?>
"><?php 
        _e('Image Size', 'epl');
        ?>
</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('image');
        ?>
" name="<?php 
        echo $this->get_field_name('image');
        ?>
">
				<?php 
        $sizes = epl_get_thumbnail_sizes();
        foreach ($sizes as $k => $v) {
            $v = implode(" x ", $v);
            echo '<option class="widefat" value="' . $k . '" id="' . $k . '"', $instance['image'] == $k ? ' selected="selected"' : '', '>', __($k, 'epl') . ' (' . __($v, 'epl') . ' )', '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('d_icons');
        ?>
"><?php 
        _e('Icon Style', 'epl');
        ?>
</label>
			<select class="widefat" id="<?php 
        echo $this->get_field_id('d_icons');
        ?>
" name="<?php 
        echo $this->get_field_name('d_icons');
        ?>
">
				<?php 
        $options = array('none', 'all', 'beds/baths');
        foreach ($options as $option) {
            echo '<option value="' . $option . '" id="' . $option . '"', $instance['d_icons'] == $option ? ' selected="selected"' : '', '>', __($option, 'epl'), '</option>';
        }
        ?>
			</select>
		</p>
		
		<p>
			<select id="<?php 
        echo $this->get_field_id('p_number');
        ?>
" name="<?php 
        echo $this->get_field_name('p_number');
        ?>
">
				<?php 
        for ($i = 1; $i <= 20; $i++) {
            echo '<option value="' . $i . '"';
            if ($i == $instance['p_number']) {
                echo ' selected="selected"';
            }
            echo '>' . __($i, 'epl') . '</option>';
        }
        ?>
			</select>
			<label for="<?php 
        echo $this->get_field_id('p_number');
        ?>
"><?php 
        _e('Number of Properties', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<select id="<?php 
        echo $this->get_field_id('p_skip');
        ?>
" name="<?php 
        echo $this->get_field_name('p_skip');
        ?>
">
				<?php 
        for ($i = 0; $i <= 20; $i++) {
            echo '<option value="' . $i . '"';
            if ($i == $instance['p_skip']) {
                echo ' selected="selected"';
            }
            echo '>' . __($i, 'epl') . '</option>';
        }
        ?>
			</select>
			<label for="<?php 
        echo $this->get_field_id('p_skip');
        ?>
"><?php 
        _e('Properties to Skip', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('featured');
        ?>
" name="<?php 
        echo $this->get_field_name('featured');
        ?>
" <?php 
        if ($instance['featured']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('featured');
        ?>
"><?php 
        _e('Only Show Featured Properties', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('d_title');
        ?>
" name="<?php 
        echo $this->get_field_name('d_title');
        ?>
" <?php 
        if ($instance['d_title']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('d_title');
        ?>
"><?php 
        _e('Property Headline', 'epl');
        ?>
</label>
		</p>

		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('d_excerpt');
        ?>
" name="<?php 
        echo $this->get_field_name('d_excerpt');
        ?>
" <?php 
        if ($instance['d_excerpt']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('d_excerpt');
        ?>
"><?php 
        _e('Excerpt', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('d_suburb');
        ?>
" name="<?php 
        echo $this->get_field_name('d_suburb');
        ?>
" <?php 
        if ($instance['d_suburb']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('d_suburb');
        ?>
"><?php 
        echo epl_labels('label_suburb');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('d_street');
        ?>
" name="<?php 
        echo $this->get_field_name('d_street');
        ?>
" <?php 
        if ($instance['d_street']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('d_street');
        ?>
"><?php 
        _e('Street Address', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('d_price');
        ?>
" name="<?php 
        echo $this->get_field_name('d_price');
        ?>
" <?php 
        if ($instance['d_price']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('d_price');
        ?>
"><?php 
        _e('Price', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('more_text');
        ?>
"><?php 
        _e('Read More Label', 'epl');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('more_text');
        ?>
" name="<?php 
        echo $this->get_field_name('more_text');
        ?>
" type="text" value="<?php 
        echo $more_text;
        ?>
" />
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('d_more');
        ?>
" name="<?php 
        echo $this->get_field_name('d_more');
        ?>
" <?php 
        if ($instance['d_more']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('d_more');
        ?>
"><?php 
        _e('Read More Button', 'epl');
        ?>
</label>
		</p>

		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('archive');
        ?>
" name="<?php 
        echo $this->get_field_name('archive');
        ?>
" <?php 
        if ($instance['archive']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('archive');
        ?>
"><?php 
        _e('Dynamic', 'epl');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('order_rand');
        ?>
" name="<?php 
        echo $this->get_field_name('order_rand');
        ?>
" <?php 
        if ($instance['order_rand']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('order_rand');
        ?>
"><?php 
        _e('Random Order', 'epl');
        ?>
</label>
		</p>
        <?php 
    }
Example #7
0
    function form($instance)
    {
        $defaults = array('post_type' => array('property', 'rental', 'land', 'rural', 'commercial', 'business', 'commercial_land', 'location_profile'), 'limit' => '30', 'coords' => '', 'display' => 'card', 'zoom' => '17', 'height' => '', 'cluster' => false, 'property_status' => '', 'home_open' => false, 'location' => '');
        $instance = wp_parse_args((array) $instance, $defaults);
        extract($instance);
        ?>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('post_type');
        ?>
"><?php 
        _e('Listing Type, hold CTRL to select multiple', 'epl-am');
        ?>
</label> 
			<select multiple class="widefat" id="<?php 
        echo $this->get_field_id('post_type');
        ?>
" name="<?php 
        echo $this->get_field_name('post_type');
        ?>
[]">
				<?php 
        $supported_post_types = epl_get_active_post_types();
        if (!empty($supported_post_types)) {
            foreach ($supported_post_types as $k => $v) {
                $selected = '';
                if (in_array($k, $post_type)) {
                    $selected = 'selected="selected"';
                }
                echo '<option value="' . $k . '" ' . $selected . '>' . __($v, 'epl-am') . '</option>';
            }
        }
        ?>
			</select>
		</p>
		
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('limit');
        ?>
"><?php 
        _e('Limit:', 'epl-am');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('limit');
        ?>
" name="<?php 
        echo $this->get_field_name('limit');
        ?>
" type="number" value="<?php 
        echo $limit;
        ?>
" />
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('coords');
        ?>
"><?php 
        _e('Map centre coordinates:', 'epl-am');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('coords');
        ?>
" name="<?php 
        echo $this->get_field_name('coords');
        ?>
" type="text" value="<?php 
        echo $coords;
        ?>
" />
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('display');
        ?>
"><?php 
        _e('Display Type', 'epl-am');
        ?>
</label> 
			 <select class="widefat" id="<?php 
        echo $this->get_field_id('display');
        ?>
" name="<?php 
        echo $this->get_field_name('display');
        ?>
">
                <option value="">  <?php 
        _e("Display type", "epl-am");
        ?>
  </option>
                <?php 
        $display_types = array('card', 'slider', 'simple', 'popup');
        foreach ($display_types as $display_type) {
            $selected = '';
            if ($display_type == $display) {
                $selected = ' selected="selected" ';
            }
            echo '<option value="' . $display_type . '" ' . $selected . '>' . __($display_type, 'epl-am') . '</option>';
        }
        ?>
            </select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('zoom');
        ?>
"><?php 
        _e('Zoom Level', 'epl-am');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('zoom');
        ?>
" name="<?php 
        echo $this->get_field_name('zoom');
        ?>
" type="number" value="<?php 
        echo $zoom;
        ?>
" />
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('height');
        ?>
"><?php 
        _e('Map Height', 'epl-am');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('height');
        ?>
" name="<?php 
        echo $this->get_field_name('height');
        ?>
" type="number" value="<?php 
        echo $height;
        ?>
" />
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('cluster');
        ?>
" name="<?php 
        echo $this->get_field_name('cluster');
        ?>
" <?php 
        if ($instance['cluster']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('cluster');
        ?>
"><?php 
        _e('Allow Marker Clustering', 'epl-am');
        ?>
</label>
		</p>
		
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('home_open');
        ?>
" name="<?php 
        echo $this->get_field_name('home_open');
        ?>
" <?php 
        if ($instance['home_open']) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('home_open');
        ?>
"><?php 
        _e('Only show listings open for inspection', 'epl-am');
        ?>
</label>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('property_status');
        ?>
"><?php 
        _e('Property Status', 'epl-am');
        ?>
</label> 
			 <select  multiple class="widefat" id="<?php 
        echo $this->get_field_id('property_status');
        ?>
" name="<?php 
        echo $this->get_field_name('property_status');
        ?>
[]">
                <option value="">  <?php 
        _e("Property Status", "epl-am");
        ?>
  </option>
                <?php 
        $status_types = array('current' => __('Current', 'epl-am'), 'withdrawn' => __('Withdrawn', 'epl-am'), 'offmarket' => __('Off Market', 'epl-am'), 'sold' => __('Sold', 'epl-am'));
        foreach ($status_types as $k => $status_type) {
            $selected = '';
            if (in_array($k, $property_status)) {
                $selected = 'selected="selected"';
            }
            ?>
                        <option <?php 
            echo $selected;
            ?>
 value="<?php 
            echo esc_html($k);
            ?>
"><?php 
            echo esc_html($status_type);
            ?>
</option>
                        <?php 
        }
        ?>
            </select>
		</p>
		
		<p>
			<label for="<?php 
        echo $this->get_field_id('location');
        ?>
"><?php 
        _e('Location', 'epl-am');
        ?>
</label> 
			 <select class="widefat" id="<?php 
        echo $this->get_field_id('location');
        ?>
" name="<?php 
        echo $this->get_field_name('location');
        ?>
">
                <option value="">  <?php 
        _e("All locations", "epl-am");
        ?>
  </option>
                 <?php 
        $locations = get_terms('location');
        foreach ($locations as $this_location) {
            $selected = '';
            if ($location == $this_location->slug) {
                $selected = ' selected="selected" ';
            }
            ?>
                        <option <?php 
            echo $selected;
            ?>
 value="<?php 
            echo esc_html($this_location->slug);
            ?>
"><?php 
            echo esc_html($this_location->name);
            ?>
</option>
                        <?php 
        }
        ?>
            </select>
		</p>
		
		<?php 
    }