Easy Property Listings 3.5.15 Code Reference
  • Package
  • Class
  • Tree
  • Todo
  • Hook Reference

Packages

  • EPL
    • Admin
      • Actions
      • Classes
        • ContactsTable
        • ReportsGraph
        • Welcome
      • Contacts
      • ContactsActions
      • ContactsFunctions
      • Elements
      • Functions
      • Help
      • HelpSingle
      • Menus
      • MenusAddons
      • MenusExtensions
      • MenusLicenses
      • Plugins
      • Reports
      • ReportsGraphing
      • User
    • Assets
      • ScriptsStyles
      • SVG
    • Classes
      • AuthorLoader
      • AuthorMeta
      • Contact
      • Cron
      • CustomPostType
      • Forms
      • License
      • ListingAdvanced
      • ListingElements
      • MetaboxesCustomFields
      • Pagination
      • PropertyMeta
      • RenderFields
      • RestAPI
      • Search
      • Session
      • Updater
    • Compatibility
      • Extensions
      • Functions
      • Shortcodes
    • Functions
      • Actions
      • ConditionalTags
      • ErrorTracking
      • Formatting
      • Front
      • Global
      • Install
      • Pagination
      • Settings
      • Templates
    • Hooks
      • EnergyCertificate
      • ExternalLinks
      • FloorPlan
      • Map
      • ReadMore
      • WebLink
    • Meta
      • InitCustomFields
      • Meta
    • PostTypes
      • Business
      • Commercial
      • CommercialLand
      • Contact
      • Functions
      • Land
      • Property
      • Rental
      • Rural
    • Shortcode
      • CommercialListingSearch
      • ContactForm
      • Listing
      • ListingAdvanced
      • ListingAuction
      • ListingCategory
      • ListingFeature
      • ListingLocation
      • ListingMetaDoc
      • ListingOpen
      • ListingResults
      • ListingSearch
      • Map
    • Taxonomy
      • BusinessCategories
      • ContactTag
      • Features
      • Location
    • Templates
      • Themes
        • iThemes
        • iThemesBuilder
    • Widget
      • Admin
        • Dashboard
      • Classes
        • Author
        • ContactCapture
        • Gallery
        • Listing
        • Search
      • Functions
  • None
  • WordPress
    • Session

Classes

  • EPL_Advanced_Shortcode_Listing
  • EPL_Author
  • EPL_Author_Loader
  • EPL_Author_Meta
  • EPL_Contact
  • EPL_Contact_Reports_Table
  • EPL_CPT
  • EPL_Cron
  • EPL_FORM_BUILDER
  • EPL_Graph
  • EPL_License
  • EPL_Listing_Elements
  • EPL_METABOX
  • EPL_Pagination_Call
  • EPL_Property_Meta
  • EPL_Render_Fields
  • EPL_Rest_API
  • EPL_SEARCH
  • EPL_Search_Fields
  • EPL_Session
  • EPL_SL_Plugin_Updater
  • EPL_Welcome
  • EPL_Widget_Author
  • EPL_Widget_Contact_Capture
  • EPL_Widget_Property_Gallery
  • EPL_Widget_Property_Search
  • EPL_Widget_Recent_Property

Functions

  • EPL
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 
<?php
/**
 * SHORTCODE :: Listing Category [listing_category]
 *
 * @package     EPL
 * @subpackage  Shortcode/ListingCategory
 * @copyright   Copyright (c) 2019, Merv Barrett
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.1.1
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// phpcs:disable WordPress.DB.SlowDBQuery

/**
 * Listing Category [listing_category]
 *
 * This shortcode allows for you to specify the property type(s) using
 * [listing_category post_type="property" status="current,sold,leased" category_key="property_rural_category" category_key="farm"] option. You can also
 * limit the number of entries that display. using  [listing_category limit="5"]
 * Added Commercial Category Support
 *
 * @param array $atts Shortcode attributes.
 *
 * @return false|string|void
 * @since 1.1.1
 * @since 3.5 support for third and fourth agents.
 * @since 3.4.48 Fixed class name.
 * @since 3.5.5 Sorting not working.
 */
function epl_shortcode_listing_category_callback( $atts ) {
    $property_types = epl_get_active_post_types();
    if ( ! empty( $property_types ) ) {
        $property_types = array_keys( $property_types );
    }

    $attributes = shortcode_atts(
        array(
            'post_type'               => $property_types,
            'status'                  => array( 'current', 'sold', 'leased' ),
            'commercial_listing_type' => '',     // Listing Type, 'sale' , 'lease', 'both'.
            'category_key'            => '',     // Meta field key.
            'category_value'          => '',     // Meta field value.
            'category_compare'        => 'IN',   // Compare using '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'EXISTS', 'NOT EXISTS', 'IN','NOT IN','BETWEEN','NOT BETWEEN'.
            'limit'                   => '10',   // Number of maximum posts to show.
            'offset'                  => '',     // Offset posts. When used, pagination is disabled.
            'author'                  => '',     // Author of listings.
            'agent'                   => '',     // Agent of listings.
            'template'                => false,  // Template can be set to "slim" for home open style template.
            'location'                => '',     // Location slug. Should be a name like sorrento.
            'tools_top'               => 'off',  // Tools before the loop like Sorter and Grid on or off.
            'tools_bottom'            => 'off',  // Tools after the loop like pagination on or off.
            'sortby'                  => '',     // Options: price, date, status, rand (for random) : Default date.
            'sort_order'              => 'DESC', // Sort by ASC or DESC.
            'pagination'              => 'on',   // Enable or disable pagination.
            'instance_id'             => '1',    // Set instance ID when using multiple shortcodes on the same page.
            'class'                   => '',     // Custom class.
        ),
        $atts
    );

    $post_type               = $attributes['post_type'];
    $status                  = $attributes['status'];
    $commercial_listing_type = $attributes['commercial_listing_type'];
    $category_key            = $attributes['category_key'];
    $category_value          = $attributes['category_value'];
    $category_compare        = $attributes['category_compare'];
    $limit                   = $attributes['limit'];
    $offset                  = $attributes['offset'];
    $author                  = $attributes['author'];
    $agent                   = $attributes['agent'];
    $template                = $attributes['template'];
    $location                = $attributes['location'];
    $tools_top               = $attributes['tools_top'];
    $tools_bottom            = $attributes['tools_bottom'];
    $sortby                  = $attributes['sortby'];
    $sort_order              = $attributes['sort_order'];
    $pagination              = $attributes['pagination'];
    $instance_id             = $attributes['instance_id'];
    $class                   = $attributes['class'];

    if ( empty( $post_type ) ) {
        return;
    }

    if ( is_string( $post_type ) && 'rental' === $post_type ) {
        $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,
    );

    // Offset query does not work with pagination.
    if ( ! empty( $offset ) ) {
        $args['offset'] = $offset;
        $pagination     = 'off'; // Disable pagination when offset is used.
    }

    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',
            );
        }
    }

    // Listings of specified author.
    if ( ! empty( $author ) ) {
        $author = (array) $author;
        if ( is_array( $author ) ) {
            $author_ids = array_map( 'epl_get_author_id_from_name', $author );
            $author     = implode( ',', $author_ids );
        }
        $args['author'] = trim( $author );
    }

    // Listings by specified agent.
    if ( ! empty( $agent ) ) {

        $agent            = array_map( 'trim', explode( ',', $agent ) );
        $agent            = array_filter( $agent );
        $agent_meta_query = array(
            'relation' => 'OR',
        );

        foreach ( $agent as $single_agent ) {
            $agent_meta_query[] = array(
                'key'     => 'property_agent',
                'value'   => array( $single_agent, sanitize_user( $single_agent ) ),
                'compare' => 'IN',
            );
            $agent_meta_query[] = array(
                'key'     => 'property_second_agent',
                'value'   => array( $single_agent, sanitize_user( $single_agent ) ),
                'compare' => 'IN',
            );

            if ( in_array( 'commercial', $post_type, true ) ||
                in_array( 'commercial_land', $post_type, true ) ||
                in_array( 'business', $post_type, true )
            ) {

                $agent_meta_query[] = array(
                    'key'     => 'property_third_agent',
                    'value'   => array( $single_agent, sanitize_user( $single_agent ) ),
                    'compare' => 'IN',
                );
                $agent_meta_query[] = array(
                    'key'     => 'property_fourth_agent',
                    'value'   => array( $single_agent, sanitize_user( $single_agent ) ),
                    'compare' => 'IN',
                );

            }
        }

        $args['meta_query'][] = $agent_meta_query;
    }

    if ( ! empty( $commercial_listing_type ) ) {
        if ( ! is_array( $commercial_listing_type ) ) {
            $commercial_listing_type = explode( ',', $commercial_listing_type );
            $commercial_listing_type = array_map( 'trim', $commercial_listing_type );

            $args['meta_query'][] = array(
                'key'     => 'property_com_listing_type',
                'value'   => $commercial_listing_type,
                'compare' => 'IN',
            );
        }
    }

    if ( ! empty( $category_key ) && ! empty( $category_value ) ) {

        if ( ! is_array( $category_value ) && in_array( $category_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true ) ) {
            $category_value = explode( ',', $category_value );
            $category_value = array_map( 'trim', $category_value );
        }

        $this_meta_query = array(
            'key'     => $category_key,
            'value'   => $category_value,
            'compare' => $category_compare,
        );

        if ( in_array( $category_compare, array( 'BETWEEN', 'NOT BETWEEN' ), true ) ) {

            if ( is_numeric( $category_value[0] ) ) {
                $this_meta_query['type'] = 'numeric';
            }
        }
        $args['meta_query'][] = $this_meta_query;
    }

    if ( ! empty( $sortby ) ) {

        if ( 'price' === $sortby ) {
            $args['orderby']  = 'meta_value_num';
            $args['meta_key'] = $meta_key_price;
        } elseif ( 'rand' === $sortby ) {
            $args['orderby'] = 'rand';
        } elseif ( 'status' === $sortby ) {
            $args['orderby']  = 'meta_value';
            $args['meta_key'] = 'property_status';
        } else {
            $args['orderby'] = 'post_date';
        }
        $args['order'] = $sort_order;
    }

    $args['instance_id'] = $attributes['instance_id'];
    // add sortby arguments to query, if listings sorted by $_GET['sortby'];.
    $args = epl_add_orderby_args( $args, 'shortcode', 'listing_category' );

    // Option to filter args.
    $args = apply_filters( 'epl_shortcode_listing_category_args', $args, $attributes );

    $query_open = new WP_Query( $args );
    if ( $query_open->have_posts() ) { ?>
        <div class="loop epl-shortcode">
            <div class="loop-content epl-shortcode-listing-category <?php echo ' ' . esc_attr( epl_template_class( $template, 'archive' ) ) . ' ' . esc_attr( $attributes['class'] ); ?>">
                <?php
                if ( 'on' === $tools_top ) {
                    do_action( 'epl_property_loop_start', $attributes );
                }
                while ( $query_open->have_posts() ) {
                    $query_open->the_post();

                    $template = str_replace( '_', '-', $template );
                    epl_property_blog( $template );
                }
                if ( 'on' === $tools_bottom ) {
                    do_action( 'epl_property_loop_end' );
                }
                ?>
            </div>
            <div class="loop-footer">
                <?php
                if ( 'on' === $pagination ) {
                    do_action( 'epl_pagination', array( 'query' => $query_open ) );
                }
                ?>
            </div>
        </div>
        <?php
    } else {
        do_action( 'epl_shortcode_results_message', 'category' );
    }
    wp_reset_postdata();
    return ob_get_clean();
}
add_shortcode( 'listing_category', 'epl_shortcode_listing_category_callback' );
Easy Property Listings 3.5.15 Code Reference API documentation generated by ApiGen