epl_get_listing_status_label(): For Sale, Sold, For Rent or Leased label for the current listing
Description #
Returns a short status label for the current listing, for listing cards and headings: For Sale, Auction, Sold, For Rent, Leased, or Buy, Lease or Buy or Lease for commercial listings. The filter of the same name changes the result.
Usage #
echo esc_html( epl_get_listing_status_label() ); add_filter( 'epl_get_listing_status_label', 'my_function', 10, 4 );
The rules #
- Rentals: current is For Rent, leased is Leased.
- Commercial: current is Buy, Lease or Buy or Lease from the Commercial Listing Type (sale, lease, anything else); sold is Sold; leased is Leased.
- Every other listing type (property, land, rural, business, commercial land): current is Auction when the authority is auction, otherwise For Sale; sold is Sold.
- Any other status (withdrawn, off market, or leased on a sales type) returns ''. Outside a listing it returns ''.
Sold and Leased use the Sold Label and Leased Label settings (Settings > Labels). The status comes from epl_get_listing_status(). Style it with your own class; for the sticker styles see How to style the stickers.
Parameters #
Function:
$labels (array)
Labels to override, optional. Keys and defaults: label_for_sale (For Sale), label_auction (Auction), label_sold (Sold Label setting), label_for_lease (For Rent), label_leased (Leased Label setting), label_commercial_sale (Buy), label_commercial_lease (Lease), label_commercial_both (Buy or Lease), label_commercial_sold (Sold Label setting), label_commercial_leased (Leased Label setting).
Returns a string.
Filter:
$label (string)
The label, or ''.
$status (string)
The listing status from epl_get_listing_status().
$post_type (string)
The listing type, for example property or rental.
$labels (array)
All the labels, with any overrides passed to the function.
Examples #
Show the label on a listing card, with For Rent shown as To Let:
$label = epl_get_listing_status_label( array( 'label_for_lease' => 'To Let' ) );
if ( $label ) {
echo '<span class="my-status-label">' . esc_html( $label ) . '</span>';
}
Show Under Offer for current sales listings that are under offer (see Price rules for is_under_offer()):
function my_epl_status_label_under_offer( $label, $status, $post_type ) {
global $property;
if ( 'current' === $status && 'rental' !== $post_type && $property->is_under_offer() ) {
return __( 'Under Offer', 'my-theme' );
}
return $label;
}
add_filter( 'epl_get_listing_status_label', 'my_epl_status_label_under_offer', 10, 3 );
Source #
lib/includes/functions.php, in epl_get_listing_status_label(). Since 3.6.